Skip to Content

TypeScript library

Scaffold a standalone TypeScript package with the create-app typescript-library template, and add OSDK code that apps can share.

The typescript-library template of @osdk/create-app creates a TypeScript package that builds ESM and type declarations with tsc, tests with Vitest, and lints with Ultracite. Use it to start a package of shared code, such as Ontology helpers that several of your OSDK apps import.

This template is beta and hidden from the CLI's framework list. Select it with --template typescript-library. It contains no OSDK code or dependencies; you add those yourself.

When to use it

You want toUse
Share functions, types, or object-set helpers between several appsThis template
Build a browser appThe react, vue, or expo template. See Quickstart.
Run a script, server, or serverless functionA plain Node project. See Node.js.

Create the library

Run @osdk/create-app with the template, and pass --skipOsdk to skip the SDK prompts. --skipOsdk only works with an explicit --sdkVersion 2.x:

npx @osdk/create-app@latest my-library --template typescript-library --sdkVersion 2.x --skipOsdk

The CLI still asks for a Foundry URL, application RID, client ID, application URL, CORS proxy, and scopes, and writes .env.development, .env.production, .npmrc, and foundry.config.json from them. The library does not read the .env files or foundry.config.json; delete them if you do not need them. Keep .npmrc if you will install your SDK from the Foundry registry. It holds only the token line, so add your SDK's @scope:registry= line as described in Installation.

Then install and build:

cd my-library
npm install
npm run build

Project structure

AGENTS.md
oxfmt.config.ts
oxlint.config.ts
package.json
tsconfig.json
index.ts
index.test.ts
FilePurpose
src/index.tsThe package entry point. Everything it exports is the library's public API. The template exports a sample greet function.
src/__tests__/Vitest tests. tsconfig.json excludes them from the build.
package.jsonAn ESM package ("type": "module") whose exports, main, and types point at dist/. Only dist/ is published.
tsconfig.jsonStrict settings that compile src/ to dist/ with declaration files, declaration maps, and source maps. Targets ES2022.
oxlint.config.ts, oxfmt.config.tsThe Ultracite presets for oxlint and oxfmt. Lint warns on function expressions and prefers named function declarations.
AGENTS.md, .claude/Coding standards for AI agents. .claude/settings.json runs npx ultracite fix after every file edit Claude Code makes.
.vscode/extensions.jsonRecommends the Oxc extension.

Scripts

ScriptRunsDoes
buildtscType-checks and emits JavaScript and .d.ts files to dist/.
cleanrm -rf distDeletes the build output.
testvitest runRuns the tests once.
test:watchvitestRuns the tests in watch mode.
lintultracite checkChecks formatting and lint rules.
fixultracite fixFixes formatting and lint issues.
formatoxfmt .Formats every file.

The generated README.md mentions npm run check. The script is named lint.

Add OSDK code

Install @osdk/client and your SDK. Your SDK comes from your Foundry npm registry, so set up .npmrc first as described in Installation:

npm install --save-dev @osdk/client @my-app/sdk

Also list both in peerDependencies, so an app that installs your library provides them. The app and your library then share one @osdk/client and one copy of the SDK. Your generated SDK already declares @osdk/client as a peer.

Take the Client as a parameter instead of creating one in the library. The app keeps a single client with its own authentication, and your functions use it:

src/engineers.ts
import { Employee } from "@my-app/sdk";
import type { Client, Osdk } from "@osdk/client";

export async function listEngineers(
  client: Client,
): Promise<Osdk.Instance<Employee>[]> {
  const engineers: Osdk.Instance<Employee>[] = [];
  for await (const employee of client(Employee)
    .where({ department: "Engineering" })
    .asyncIter()) {
    engineers.push(employee);
  }
  return engineers;
}

Export it from the entry point:

src/index.ts
export { listEngineers } from "./engineers.js";

tsc does not rewrite import paths. Write relative imports with the .js extension, as above, so dist/ also loads in Node.js without a bundler. Create a client lists the client methods you can call.

On this page