Skip to content
Browse documentation
typescript sdk

Browser-safe contracts and OpenAPI

Optionally project trusted contract modules for browsers and export the bounded JSON OpenAPI profile.

Keep server authoring out of the browser

Ordinary shared imports work without a generator. Optional tooling replaces selected browser runtime exports with validated descriptors; TypeScript still checks the original source and the server still runs it.

// vite.config.ts
import { defineConfig } from "vite";
import { serviceBrowserContracts } from "@smoothie-framework/service/vite";

export default defineConfig({
  plugins: [serviceBrowserContracts({
    modules: [{
      file: new URL("./shared/contracts.ts", import.meta.url),
      exports: ["ReadStatus"],
    }],
  })],
});

Select handler-free modules explicitly. They run as trusted local build code, not in a sandbox. This is not a secret-removal scanner. Keep reusable schema value exports separate.

Rspack uses ServiceBrowserContractsPlugin from service/rspack with the same module selection. Build integrations belong in bundler configuration, never browser runtime code.

Export the portable JSON profile

import {
  createServiceOpenApiDocument,
  validateServiceOpenApiDocument,
} from "@smoothie-framework/service";

The bounded OpenAPI 3.1.1 exporter requires operation IDs and status-specific schemas. It does not generate clients/servers or cover every OpenAPI feature. Native file, stream and cookie semantics are outside this JSON profile.

See Contracts and JSON validation for schema limits. Browser projection and OpenAPI export are independent, optional operations.