import type { ServicePlugin, Store } from '../core/index.js'; import type { WorkOSConnectionType, PipeProvider, PipeConnectionStatus, ConnectedAccountState, ConnectionOwner } from './entities.js'; export { getWorkOSStore, type WorkOSStore } from './store.js'; export * from './entities.js'; export interface WorkOSSeedOrganization { /** * Pinned organization id (e.g. `org_01ABC…`). Generated if omitted. Pin it to match * what your real WorkOS environment emits, so a backend whose database already * references a real org id lines up with the emulator across restarts. */ id?: string; name: string; external_id?: string; metadata?: Record; domains?: Array<{ domain: string; state?: 'verified' | 'pending'; }>; allow_profiles_outside_organization?: boolean; /** Entitlement slugs minted into the `entitlements` claim of org-scoped access tokens. */ entitlements?: string[]; /** * The organization's authentication policy allows SSO only: hosted AuthKit sends the people the * policy governs to the organization's SSO connection. Defaults to false, which keeps the * hosted sign-in. */ require_sso?: boolean; /** * The organization's domain policy: which of its verified `domains` it covers. Its settings * then apply to every address on those domains, member or not. A domain can be in one * organization's policy only. */ domain_policy?: string[]; memberships?: Array<{ /** * Pinned membership id (e.g. `om_01ABC…`). Generated if omitted. Pin it when a backend * stores the membership id and later addresses the membership by it (role changes, * removal), so the stored id still resolves after an emulator restart. */ id?: string; /** * Email of a user defined in `users`. Seeded user ids are generated at startup, * so memberships are joined by email — an id literal could never resolve. */ email: string; role?: string; /** * Every role the membership holds — the shape production stores once multiple roles are * enabled. `role` and the order of `roles` follow the role priority, as in production. Use * this or `role`, not both. */ roles?: string[]; status?: 'active' | 'inactive' | 'pending'; }>; /** * AuthKit groups within this organization. Members reference a membership of this * org by the user's email — the same join key `memberships` use — because org * membership ids are generated at startup, so an id literal could never resolve. */ groups?: Array<{ name: string; description?: string | null; /** Emails of users that have a membership in this organization. */ members?: string[]; }>; } export interface WorkOSSeedUser { /** * Pinned user id (e.g. `user_01ABC…`). Generated if omitted. Pin it to match what your * real WorkOS environment emits, so the identity stays stable across emulator restarts * and can line up with an existing operator in a copied application database. */ id?: string; email: string; name?: string; first_name?: string; last_name?: string; password?: string; email_verified?: boolean; external_id?: string; metadata?: Record; impersonator?: { email: string; reason: string; }; /** * The OAuth provider this user authenticates with, reported as the authentication_method for * OAuth-based grants (authorization_code, refresh_token, device_code). Must be a spec-valid * value such as 'GoogleOAuth' or 'MicrosoftOAuth'. When omitted the emulator leaves * authentication_method off the response rather than guessing a provider. * * Setting it also links an OAuth identity, so the user is returned by * `GET /user_management/users/{id}/identities` and readable as `user.identities` in a JWT * template. */ oauth_provider?: string; /** * The user's id at `oauth_provider`, reported as the linked identity's `idp_id`. Generated if * omitted. Pin it to match what your real WorkOS environment emits. Ignored without * `oauth_provider` — there is no identity to put it on. */ oauth_idp_id?: string; /** * Enroll a TOTP authentication factor for this user at boot, exactly as * `POST /user_management/users/{id}/auth_factors` would. The factor is reported by * `GET /user_management/users/{id}/auth_factors`, and a password sign-in answers with the * spec's `mfa_challenge` step instead of a session — so MFA administration and step-up * login flows are testable without post-boot enrollment calls that in-memory state loses * on restart. */ totp?: boolean; } export interface WorkOSSeedDirectory { name: string; /** Organization name, the same lookup key `connections` uses. */ organization: string; /** Provider descriptor, e.g. `okta scim v2.0`. Free text, as the spec's list is open. */ type?: string; state?: 'linked' | 'unlinked' | 'invalid_credentials'; domain?: string; external_key?: string; /** * Directory groups. A bare string declares a group with no role mapping; the object form * maps the group to an organization role, the way a directory's role assignments do in * the dashboard. */ groups?: Array; users?: Array<{ email: string; first_name?: string; last_name?: string; username?: string; idp_id?: string; state?: 'active' | 'inactive'; /** Names from this directory's `groups`. */ groups?: string[]; /** Overrides the role mapped from `groups`. */ role?: string; custom_attributes?: Record; }>; } export interface WorkOSSeedConnection { name: string; connection_type?: WorkOSConnectionType; organization: string; state?: 'active' | 'inactive' | 'validating'; domains?: string[]; profiles?: Array<{ email: string; first_name?: string; last_name?: string; /** * The full name as its own attribute, the way production stores it. Null when omitted — * never composed from `first_name` and `last_name`. */ name?: string; idp_id?: string; groups?: string[]; }>; } export interface WorkOSSeedPipeConnection { user_id: string; provider: PipeProvider; scopes: string[]; status?: PipeConnectionStatus; external_account_id?: string; } export interface WorkOSSeedConnectedAccount { /** * Email of a user defined in `users` — the same join key memberships use, because seeded * user ids are generated at startup unless pinned. Required for a user-owned account; for an * organization-owned one it is optional and names the member who established it. */ email?: string; /** * `organization` seeds the organization's own account, which `organization` must name and * `/organizations/{id}/connected_accounts/{slug}` serves. Defaults to `user`. */ owner?: ConnectionOwner; /** Provider slug the account is addressed by in the API path (`github`, `slack`, `notion`, …). */ provider: string; /** * Name of an organization defined in `organizations`, for a connection scoped to one. * Lookups filter by `?organization_id=…`: a user's lone account for a provider resolves * without it, while several scoped ones must name theirs, matching the API's 409. */ organization?: string; /** OAuth scopes granted for the connection. */ scopes?: string[]; /** * Defaults to `connected` — saying a user has a connected account is saying it is * connected. `disconnected` is not seedable: a disconnected account is a deleted one, * observable only in the event stream. */ state?: ConnectedAccountState; } export interface WorkOSSeedInvitation { email: string; organization_id?: string; inviter_user_id?: string; role_slug?: string; } export interface WorkOSSeedRole { slug: string; name: string; description?: string; type?: 'EnvironmentRole' | 'OrganizationRole'; organization_id?: string; is_default_role?: boolean; priority?: number; permissions?: string[]; resource_type_slug?: string; } export interface WorkOSSeedPermission { slug: string; name: string; description?: string; resource_type_slug?: string; } export interface WorkOSSeedWebhookEndpoint { /** * Where deliveries go. Any URL the receiver answers on: `POST /webhook_endpoints` holds a URL to * HTTPS as production does (loopback hosts excepted), so an `http://` receiver elsewhere is * registered here. */ endpoint_url?: string; /** @deprecated Use endpoint_url */ url?: string; /** * Event names to deliver, from the subscribable catalog in `src/workos/generated/events.ts`. * Omitted or empty subscribes the endpoint to every event — a seed-only convenience; the API * requires at least one name, as production does. */ events?: string[]; /** `enabled` (the default) or `disabled`, as `PATCH /webhook_endpoints/:id` sets it. */ status?: 'enabled' | 'disabled'; /** @deprecated Use status */ enabled?: boolean; /** * Pinned signing secret. Generated if omitted. Pin it to bake the secret into a * consumer's environment, so it can verify `WorkOS-Signature` headers on seeded * deliveries without first discovering the secret via `GET /webhook_endpoints`. */ secret?: string; } export interface WorkOSSeedConnectApplication { name: string; /** Application type. Defaults to `m2m`. */ type?: 'm2m' | 'oauth'; /** Owning organization, by name. Required for `m2m` applications. */ organization?: string; description?: string; /** OAuth scopes granted to the application. */ scopes?: string[]; /** * The `aud` claim minted into this app's m2m tokens. Defaults to the client_id. * Pin it to match what your real WorkOS environment emits, so a JWKS consumer that * validates `aud` accepts emulator tokens unchanged. */ audience?: string; /** Pinned client_id. Generated (`client_...`) if omitted. */ client_id?: string; /** * Pinned client secret value. Generated (`secret_...`) if omitted. Stored as a * client_secret resource so the seeded application has usable credentials. Pin it * to bake a known secret into a service's environment. */ client_secret?: string; /** OAuth redirect URIs. Ignored for `m2m` applications. */ redirect_uris?: string[]; /** * `oauth` only. A third-party application (`false`) is reported with the organization it * belongs to, so `organization` is required for one. Defaults to `true`. */ is_first_party?: boolean; /** * `oauth` only. Marks a public client, as production's `clientConfidentiality: public` does: * `/oauth2/token` redeems its codes by `code_verifier` alone (a code minted without a challenge * cannot be redeemed), refuses it a client secret, and rotates its refresh tokens. * `/oauth2/authorize` requires nothing of it. */ uses_pkce?: boolean; /** * Emulator-only Standalone Connect login page, receiving an external_auth_id. Leave it out and * `/oauth2/authorize` signs users in on the AuthKit hosted page instead, as an MCP client's * dynamically registered application does. */ login_url?: string | null; } export interface WorkOSSeedAuthkitOauthResource { /** The resource indicator (RFC 8707), an absolute URI with no fragment or wildcard. Unique. */ uri: string; /** Make it the environment default. At most one entry may set it. Defaults to `false`. */ default?: boolean; } export interface WorkOSSeedApiKey { name: string; /** Owning organization, by name. Required unless `user_id` is set. */ organization?: string; /** Owning user, by id. When set, `organization` supplies the required organization_id. */ user_id?: string; /** * Pinned secret value. Must start with `sk_` to be accepted for authentication. * Generated (`sk_test_...`) if omitted. */ value?: string; /** Permission slugs assigned to the key. */ permissions?: string[]; /** Expiry timestamp (ISO 8601), or null for a key that never expires. */ expires_at?: string | null; /** Auth environment. Defaults to `production` for `sk_live_*` values, else `test`. */ environment?: string; } /** Legacy auth allow-list: maps a raw API key value to its environment. */ export type WorkOSSeedApiKeyAuthMap = Record; export interface WorkOSSeedFeatureFlag { /** * Pinned flag id (e.g. `flag_01ABC…`). Generated if omitted. Pin it to match what your * real WorkOS environment emits, so an application storing flag ids lines up across * emulator restarts. */ id?: string; /** * The key application code references. Required, unique within the environment, and URL-safe: * every route addresses a flag by slug in the path. */ slug: string; /** Display name. Defaults to the slug. */ name?: string; description?: string | null; /** Whether the flag is active in this environment at all. Defaults to true. */ enabled?: boolean; /** * Value for users and organizations matching no target — the flag's "on for everyone" * switch. Defaults to false, so a flag with targets is on for exactly those targets. */ default_value?: boolean; /** Labels the dashboard filters by. Purely descriptive. */ tags?: string[]; owner?: { email: string; first_name?: string | null; last_name?: string | null; }; /** * Resources the flag is switched on for regardless of `default_value`. Targeting is * additive, as it is in production: a target can turn a flag on but never off. */ targets?: { /** * Emails of users defined in `users`. Seeded user ids are generated at startup, so * targets are joined by email — an id literal could never resolve. */ users?: string[]; /** Names of organizations defined in `organizations`, joined the same way. */ organizations?: string[]; }; } export interface WorkOSSeedAgentBlueprint { /** Pinned blueprint id (e.g. `agent_blueprint_01ABC…`). Generated if omitted. */ id?: string; /** Required and unique within the environment, as production enforces on create. */ name: string; /** 1 to 1000 characters. Omit for no description, as production's create endpoint requires. */ description?: string; /** Slugs of permissions defined in `permissions`; the ceiling on what a minted session may hold. */ permissions?: string[]; invocable_by?: { /** Slugs of roles defined in `roles`. Empty or omitted lets any member mint a delegated session. */ role_slugs?: string[]; /** * Names of organizations defined in `organizations`, joined by name for the same reason * feature-flag targets are. Empty or omitted lets every organization invoke the blueprint. */ organizations?: string[]; }; /** * All three are required when the object is given, as on production's create endpoint. * Omitting the object uses production's defaults: 3600 / 300 / 3600 seconds. */ session_settings?: { max_age_seconds: number; access_token_ttl_seconds: number; refresh_token_ttl_seconds: number; }; } export interface WorkOSSeedSessionSettings { /** * Lifetime in seconds of the access token every `/user_management/authenticate` grant mints, * first sign-in and refresh alike. Production's "Access token duration" on the application's * Sessions tab, whose default of 300 applies when this is omitted. */ access_token_ttl_seconds?: number; } export interface WorkOSSeedJwtTemplate { /** * Template string rendering to a JSON object of claims, e.g. * `'{"urn:myapp:tenant": "{{ organization.metadata.tenant_id }}"}'`. Validated at * startup, so a malformed template fails the boot rather than the first sign-in. */ content: string; } export interface WorkOSSeedConfig { organizations?: WorkOSSeedOrganization[]; users?: WorkOSSeedUser[]; connections?: WorkOSSeedConnection[]; pipeConnections?: WorkOSSeedPipeConnection[]; /** Pipes connected accounts, served by `/user_management/users/{id}/connected_accounts/{slug}`. */ connectedAccounts?: WorkOSSeedConnectedAccount[]; invitations?: WorkOSSeedInvitation[]; roles?: WorkOSSeedRole[]; permissions?: WorkOSSeedPermission[]; webhookEndpoints?: WorkOSSeedWebhookEndpoint[]; connectApplications?: WorkOSSeedConnectApplication[]; /** * MCP resource indicators (RFC 8707). A `resource` an OAuth client sends to `/oauth2/authorize` * or `/oauth2/token` becomes the access token's `aud` when it matches one of these; otherwise * `aud` is the application's `audience`, then its `client_id`. */ resourceIndicators?: WorkOSSeedAuthkitOauthResource[]; /** * API keys. Either the legacy auth allow-list map (value → environment) or an array * of API key resources. The array form creates `api_key` records AND registers each * value in the auth allow-list so the seeded key authenticates requests. */ apiKeys?: WorkOSSeedApiKeyAuthMap | WorkOSSeedApiKey[]; /** * The environment's JWT template, whose claims are merged into every access token the * emulator mints. Seeding it means a test suite gets custom claims without a setup call. */ jwtTemplate?: WorkOSSeedJwtTemplate; /** * The environment's AuthKit session settings: production's Sessions tab, which has no API, so * the seed is the only way in. A short `access_token_ttl_seconds` lets a test reach a real * token expiry without waiting out the five-minute default. */ sessionSettings?: WorkOSSeedSessionSettings; /** * Feature flags and their targets. Production has no create-flag endpoint — flags are * made in the dashboard — so seeding is the only way to get one into the emulator. */ featureFlags?: WorkOSSeedFeatureFlag[]; /** * Directories, their groups and their users. Production has no create-directory * endpoint — a directory is connected through the dashboard or Admin Portal — so * seeding is the only way to get one into the emulator. */ directories?: WorkOSSeedDirectory[]; /** * Agent blueprints, so a test suite can mint agent tokens without a create call. Instances * and sessions are never seeded: they only come into being by minting. */ agentBlueprints?: WorkOSSeedAgentBlueprint[]; } export declare function seedFromConfig(store: Store, _baseUrl: string, config: WorkOSSeedConfig): void; export declare const workosPlugin: ServicePlugin; export default workosPlugin;