Source code
Latest version: 0.9.5
The TypeScript Node.js SDK generator outputs a fully functional TypeScript/JavaScript SDK for server-side use. It can publish the SDK to npmjs.org (or any other Node package repository).
Local
Dump the generated SDK to the local file system. Available on the open source plan.
Publish an internal package
Publish the generated SDK to a private NPM hosted by Fern. Available on the Starter plan.
Publish a public package
Publish the generated SDK to npmjs.com. Available on the Starter plan.
You can override the registry using the url
key.
Configuration options
You can customize the behavior of the TypeScript generator in generators.yml
.
You can include one or more options for config
, such as:
The following options are available:
namespaceExport
namespaceExport
: Allows you to control the name of the generated namespace export and client class. By default, the exported namespace and client are named based on the organization and API names in the Fern Definition.
Type: string
To customize these names, you can use namespaceExport
:
The result would be:
defaultTimeoutInSeconds
defaultTimeoutInSeconds
: Allows you to control the timeout of the generated client. The timeout is measured in seconds. This is useful for long-running operations. Set to"infinity"
to disable timeouts.
Type: integer or "infinity"
Default: 60
noSerdeLayer
noSerdeLayer
: Allows you to control whether (de-)serialization code is generated. Whentrue
, the client uses JSON.parse() and JSON.stringify() instead.
Type: boolean
Default: false
By default, the generated client includes a layer for serializing requests and deserializing responses. This has three benefits:
-
The client validates requests and response at runtime, client-side.
-
The client can support complex types, like
Date
andSet
. -
The generated types can stray from the wire/JSON representation to be more idiomatic. For example, when
noSerdeLayer
is disabled, all properties are camelCase, even if the server is expecting snake_case.
outputESM
outputEsm
: Allows you to control whether the generated TypeScript targetsCommonJS
oresnext
.
Type: boolean
Default: false
By default, the generated TypeScript targets CommonJS
. Set outputEsm
to true
to target esnext
instead.
outputSourceFiles
outputSourceFiles
: Allows you to control whether the generator outputs.js
andd.ts
files.
Type: boolean
Default: false
When disabled (the default), the generator outputs .js and d.ts files.
When enabled, the generator outputs raw TypeScript files.
This config is only applied when dumping the generated SDK to the local file system. It does not apply when publishing to GitHub or npm.
includeCredentialsOnCrossOriginRequests
includeCredentialsOnCrossOriginRequests
: Allows you to set withCredentials totrue
when making network requests.
Type: boolean
Default: false
To set withCredentials
to true
when making network requests, set this config to true
.
allowCustomFetcher
allowCustomFetcher
: Allows the end user to specify a custom fetcher implementation.
Type: boolean
Default: false
requireDefaultEnvironment
requireDefaultEnvironment
: When enabled, the generated client doesn’t allow the user to specify a server URL.
Type: boolean
Default: false
When disabled (the default), the generated client includes an option to override the server URL:
skipResponseValidation
skipResponseValidation
: When enabled, the generated client will never throw if the response is misshapen. Rather, the client will log the issue usingconsole.warn
and return the data (cast to the expected response type).
Type: boolean
Default: false
By default, this config is set to false
and the client will throw an error if the response from the server doesn’t match the expected type (based on how the response is modeled in the API definition). Set this config to true
to never throw an error and log the issue instead.
extraDependencies
extraDependencies
: Allows you to specify extra dependencies in the generated package.json.
Type: map<string,string>
Default: {}
This only applies when publishing to GitHub.
You can use extraDependencies to specify extra dependencies in the generated package.json
. This is useful when you utilize .fernignore
to supplement the generated client with custom code.
treatUnknownAsAny
treatUnknownAsAny
: When enabled, unknown types from Fern are generated into TypeScript usingany
.
Type: boolean
Default: false
In Fern, there’s an unknown
type that represents data that isn’t knowable at runtime. By default, these types are generated into TypeScript as the unknown
type.
noOptionalProperties
noOptionalProperties
: Allows you to prevent generating optional properties.
Type: boolean
Default: false
When enabled, the generated properties are never optional. Instead, the type is generated with | undefined
.
For example, let’s say you have the following Fern Definition:
By default, Fern’s optional<>
properties translate to optional TypeScript properties:
When noOptionalProperties
is enabled (set to true
):
useBrandedStringAliases
useBrandedStringAliases
: When enabled, string aliases are generated as branded strings. This makes each alias feel like its own type and improves compile-time safety.
Type: boolean
Default: false
For example, let’s say you have the following Fern Definition:
When useBrandedStringAliases
is disabled (the default), string aliases are generated as normal TypeScript aliases:
neverThrowErrors
neverThrowErrors
: When enabled, the client doesn’t throw errors when a non-200 response is received from the server. Instead, the response is wrapped in an ApiResponse.
Type: boolean
Default: false