WorkOS.ts overview
The WorkOS REST client: Bearer-authenticated JSON requests to https://api.workos.com through the core’s OutboundHttp.send (one timeout, a body cap, no redirects), each in a span that names the method and path template only. The API key never reaches an error, a span or a log.
Since v0.1.0
Exports Grouped by Category
config
config
The WorkOSConfig from the environment: WORKOS_API_KEY, WORKOS_CLIENT_ID, WORKOS_COOKIE_PASSWORD, and optionally WORKOS_REDIRECT_URI and WORKOS_ISSUER.
Signature
declare const config: Config.Config<WorkOSConfig>
Since v0.1.0
constructors
resolveConfig
Apply the defaults to a WorkOSConfig.
Signature
declare const resolveConfig: (options: WorkOSConfig) => ResolvedConfig
Since v0.1.0
errors
WorkOSError (class)
A WorkOS request that did not succeed: a non-2xx answer (status, WorkOS’s code, its x-request-id), or a request that could not complete (status: 0). The body stays out of it: WorkOS echoes input there.
Signature
declare class WorkOSError
Since v0.1.0
toAuthError
The AuthError for a failure no domain error describes, the WorkOSError kept as its cause.
Signature
declare const toAuthError: (error: WorkOSError) => Auth.Errors.AuthError
Since v0.1.0
unsupported
The AuthError for a core method WorkOS has no equivalent of.
Signature
declare const unsupported: (what: string) => Auth.Errors.AuthError
Since v0.1.0
models
RequestOptions (interface)
One request to WorkOS.
Signature
export interface RequestOptions<S extends Schema.Top> {
readonly method: "GET" | "POST" | "PUT" | "DELETE"
/** The path, ids already encoded (`path` builds one). */
readonly path: string
/** The span's name for it, the path template (`/user_management/users/{id}`). */
readonly route: string
readonly body?: Schema.JsonObject
readonly query?: Readonly<Record<string, string>>
/** The answer's schema; omit for an answer whose body is not read. */
readonly schema?: S
}
Since v0.1.0
ResolvedConfig (interface)
WorkOSConfig with its defaults applied.
Signature
export interface ResolvedConfig {
readonly apiKey: Redacted.Redacted
readonly clientId: string
readonly cookiePasswords: ReadonlyArray<Redacted.Redacted>
readonly baseUrl: string
readonly issuer: string
readonly redirectUri: Option.Option<string>
readonly delivery: "workos" | "app"
readonly sessionMaxAge: number
readonly clockSkewLeeway: number
}
Since v0.1.0
WorkOSConfig (interface)
How the package reaches WorkOS and seals its cookie.
Signature
export interface WorkOSConfig {
/** The environment's secret API key (`sk_…`). */
readonly apiKey: Redacted.Redacted
/** The AuthKit client id (`client_…`). */
readonly clientId: string
/**
* The password the session cookie is sealed with: at least 32 bytes. Keys
* derived from it are named by a key id, so a password listed in
* `previousCookiePasswords` still opens the cookies it sealed.
*/
readonly cookiePassword: Redacted.Redacted
/** Earlier cookie passwords, still accepted when opening a cookie. */
readonly previousCookiePasswords?: ReadonlyArray<Redacted.Redacted>
/** The API origin (default `https://api.workos.com`). */
readonly baseUrl?: string
/**
* The `iss` an access token must carry (default
* `<baseUrl>/user_management/<clientId>`). An environment on a custom
* AuthKit domain names that domain here.
*/
readonly issuer?: string
/** Where AuthKit and SSO send the browser back with a code. */
readonly redirectUri?: string
/**
* Who sends Magic Auth codes and password-reset links: WorkOS from its
* dashboard templates (`"workos"`, the default), or the app through the
* core `EmailSender` (`"app"`), with the code or token WorkOS answers. Turn
* WorkOS's own email for those off in the dashboard for `"app"`.
*/
readonly delivery?: "workos" | "app"
/**
* How long a session cookie lives, in milliseconds, from the sign-in
* (default 30 days). Match the session lifetime set in the WorkOS
* dashboard: WorkOS refuses a refresh past it whatever the cookie says.
*/
readonly sessionMaxAge?: number
/** Clock tolerance for access-token `exp`, in milliseconds (default 30 s). */
readonly clockSkewLeeway?: number
}
Since v0.1.0
services
WorkOSClient (class)
The WorkOS client.
Signature
declare class WorkOSClient
Since v0.1.0
utils
path
A path with each id URL-encoded, so an id cannot add a segment.
Signature
declare const path: (strings: TemplateStringsArray, ...ids: ReadonlyArray<string>) => string
Since v0.1.0