/** * JWT template rendering. * * A JWT template is a string in `content` that renders to a JSON object whose keys are * merged into the access tokens the emulator mints. WorkOS documents a small custom * interpolation syntax — not full Liquid — so this implements exactly that subset: * * - `{{ user.email }}` — variable interpolation over a dotted path * - `{{ user.nickname || user.email }}` — fallback chain, first non-null wins * - `{{ user.nickname || 'anonymous' }}` — single-quoted string literal as a fallback * - `"{{ user.first_name }} {{ user.last_name }}"` — concatenation inside a JSON string * - `{"meta": {{ user.metadata }}}` — whole objects and arrays, interpolated outside a string * * Filters, conditionals, and loops are not part of the syntax and are not supported. */ import { type Store } from '../core/index.js'; import type { WorkOSStore } from './store.js'; import type { WorkOSUser } from './entities.js'; /** * Claims a template may not set. WorkOS rejects these at template-update time, so the * emulator does too rather than letting a template quietly shadow the identity of the * token. Notably `aud`, `sid`, `org_id`, `role`, `roles`, and `permissions` are *not* * reserved: a template may override those, and the rendered value wins. */ export declare const RESERVED_JWT_CLAIMS: readonly ['iss', 'sub', 'exp', 'iat', 'nbf', 'jti']; /** * WorkOS caps the rendered claim set at 3072 bytes, because the session cookie that * carries it has to fit in a browser. Enforced at sign time, since the rendered size * depends on the data the claims are drawn from. */ export declare const MAX_RENDERED_CLAIMS_BYTES = 3072; export interface JwtTemplateContext { user?: Record; organization?: Record; organization_membership?: Record; } /** A template that cannot be rendered: bad syntax, unknown root, or an oversized result. */ export declare class JwtTemplateError extends Error { constructor(message: string); } /** * Render a template into claims ready to merge into a token. Top-level nulls are dropped * (a claim WorkOS would omit rather than emit as null), as are reserved claims — those are * rejected when the template is set, so this is only a backstop. */ export declare function renderJwtTemplate(content: string, context: JwtTemplateContext): Record; /** * Validate template content the way WorkOS does when it is set: it has to render to a JSON * object with at least one key, reference only known variables, and stay off the reserved * claims. Returns human-readable problems; empty means valid. */ export declare function validateJwtTemplateContent(content: unknown): string[]; /** * Assemble the variables a template can read for one sign-in. Mirrors the production * WorkOS JWT template context: `user` and `organization` are built from the format* * helpers (so they track the API response shape), with the adjustments prod's template * context makes on top — `user.identities` is added (a provider→`idp_id` map, null for every * provider the user has not linked) and `user.last_sign_in_at` is dropped. `organization_membership` * is built explicitly with the context-only shape (string `role`/`roles`, no * `external_id`/`metadata`). * * `user.name` is not on the emulator's user entity yet; it will auto-appear via * formatUser once PR #43 adds it. No change here will be needed when that lands. */ export declare function buildJwtTemplateContext(ws: WorkOSStore, user: WorkOSUser, organizationId?: string | null): JwtTemplateContext; /** * Render the environment's configured template, if one is set, into claims for a token. * Returns undefined when no template is configured. */ export declare function renderConfiguredJwtTemplate(store: Store, ws: WorkOSStore, user: WorkOSUser, organizationId?: string | null): Record | undefined;