feat: CLI management commands for all WorkOS resources#76
Open
feat: CLI management commands for all WorkOS resources#76
Conversation
Replace raw `workosRequest()` fetch calls in organization and user commands with the `@workos-inc/node` SDK. Introduce a unified client (`workos-client.ts`) that wraps the SDK for documented endpoints and extends with raw-fetch methods for undocumented ones (webhooks, redirect URIs, CORS origins, homepage URL).
Implement 12 command groups (phases 2-6) covering the full WorkOS management API surface: - role, permission (RBAC with env/org-scoped branching) - membership, invitation, session (user lifecycle) - connection, directory (SSO & directory sync, read/delete with confirm) - event, audit-log (observability with export polling) - feature-flag, webhook, config, portal, vault, api-key, org-domain Extends workos-client.ts with auditLogs extension methods for undocumented endpoints. All commands follow the established SDK client pattern with JSON/human output modes and structured error handling. 229 new tests across 16 spec files (894 total).
Add 5 orchestration commands that compose existing SDK operations: - seed: declarative YAML-based resource provisioning with state tracking and --clean teardown - setup-org: one-shot org onboarding (create, domain, roles, portal) - onboard-user: invitation workflow with optional --wait polling - debug-sso: SSO connection diagnostics with event history - debug-sync: directory sync diagnostics with user/group counts Adds yaml dependency for seed file parsing. 16 new tests (916 total).
Auto-discovered by install-skill via skills/workos-management/SKILL.md. Covers full command reference, workflow recipes (RBAC, org/user onboarding, SSO/DSync debugging, seeding), --json usage guide, and dashboard-only negative guidance.
Wire up 19 new command groups in bin.ts (role, permission, membership, invitation, session, connection, directory, event, audit-log, feature-flag, webhook, config, portal, vault, api-key, org-domain, seed, setup-org, onboard-user, debug-sso, debug-sync). Update help-json.ts with all 29 command schemas for --help --json.
Add duck-type detection for @workos-inc/node SDK exceptions alongside the existing WorkOSApiError check. SDK errors (UnauthorizedException, NotFoundException, etc.) now produce clean user-facing messages instead of crashing with "Unknown error". Revert toSnakeCase output conversion — JSON output conforms to the Node SDK's camelCase format.
Replace `as any` with proper SDK types: CreateAuditLogEventOptions for audit log events, ConnectionType for SSO connection type filter.
Replace manual console.error + process.exit(1) with exitWithError() for consistent structured error output. Partial state passed via the details field.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds 21 new CLI command groups covering the full WorkOS management API surface — RBAC, user lifecycle, SSO, directory sync, observability, config, and compound workflows. Enables both developers and AI agents to manage WorkOS resources directly from the terminal without context-switching to the dashboard.
Motivation: A WorkOS coworker spent a weekend fully integrating AuthKit, SSO, DSync, Feature Flags, Audit Logs, and RBAC — and identified leaving the editor as their biggest friction point. AI agents compound this: they can generate integration code but can't complete setup because they have no way to call WorkOS APIs. This PR brings us closer to closing that gap.
What's included
Foundation (Phase 1)
src/lib/workos-client.ts— Unified client wrapping@workos-inc/nodeSDK + raw fetch extensions for undocumented endpoints (webhooks, redirect URIs, CORS, homepage URL)organizationandusercommands from rawworkosRequest()to SDK clientNew commands (Phases 2-6)
workos rolelist,get,create,update,delete,set-permissions,add-permission,remove-permission--orgflag for org-scoped rolesworkos permissionlist,get,create,update,deleteworkos membershiplist,get,create,update,delete,deactivate,reactivateworkos invitationlist,get,send,revoke,resendworkos sessionlist,revokeworkos connectionlist,get,delete--forceconfirmation)workos directorylist,get,delete,list-users,list-groupsworkos eventlist--eventsfilter)workos audit-logcreate-event,export,list-actions,get-schema,create-schema,get-retentionworkos feature-flaglist,get,enable,disable,add-target,remove-targetworkos webhooklist,create,deleteworkos configredirect add,cors add,homepage-url setworkos portalgenerate-linkworkos vaultlist,get,get-by-name,create,update,delete,describe,list-versionsworkos api-keylist,create,validate,deleteworkos org-domainget,create,verify,deleteCompound workflows (Phase 7)
workos seed --file=<yaml>--cleanteardownworkos setup-org <name>workos onboard-user <email>--waitpolling for acceptanceworkos debug-sso <connId>workos debug-sync <dirId>Agent skill (Phase 8)
skills/workos-management/SKILL.md— Agent skill auto-discovered byworkos install-skillthat teaches AI agents command reference, workflow recipes (RBAC setup, org onboarding, SSO debugging, seeding),--jsonusage, and dashboard-only negative guidanceError handling (Phase 9)
@workos-inc/nodeSDK exceptions inapi-error-handler.ts— all SDK errors (401, 404, 422, etc.) now produce clean structured error messages instead of crashingArchitecture
createWorkOSClient(apiKey, baseUrl)per-invocation (not singleton)@workos-inc/nodedirectly; undocumented endpoints useworkosRequest()extensionscreateApiErrorHandler(resourceName)handles bothWorkOSApiError(raw fetch) and SDK exceptions (duck-typed via{ status, requestID })--jsonfor structured output (auto-enabled in non-TTY) and--api-keyfor explicit key overrideconnection deleteanddirectory deleterequire--forcein non-TTY modeseedtracks created resources in.workos-seed-state.jsonfor idempotent cleanupTest plan
vi.mock('../lib/workos-client.js')scripts/smoke-test.ts) exercises 27 command handlers against the real WorkOS API — 27/27 passingpnpm typecheck✅pnpm test✅pnpm build✅Dependencies added
@workos-inc/node— Official WorkOS Node.js SDKyaml— YAML parsing for seed command