feat: add connection create and update commands - #221
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Original prompt from quentin.balin
|
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Greptile SummaryThe PR adds CLI commands for creating and updating SSO connections through the Connections API.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
|
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
| outputJson(connection); | ||
| return; | ||
| } | ||
| outputSuccess('Created connection', connection); | ||
| } catch (error) { |
There was a problem hiding this comment.
🟡 Machine-readable output for creating and updating connections omits the standard success wrapper
The newly created/updated connection is printed as a bare object (outputJson(connection) at src/commands/connection.ts:177-181) instead of the standard success envelope every other create/update command emits, so scripts and agents that read the status field get nothing back.
Impact: Automated callers parsing JSON output of these two commands see a different shape than for all other resource create/update commands and can mis-handle the result.
Why this deviates from the established output convention
CLAUDE.md requires new resource commands to follow the patterns in src/commands/organization.ts. There, create/update call outputSuccess('Created organization', org) (src/commands/organization.ts:34, src/commands/organization.ts:56), which in JSON mode produces { status: 'ok', message, data } (src/utils/output.ts:66-85). The same convention is used by role.ts (src/commands/role.ts:87, src/commands/role.ts:116) and by runConnectionDelete in this very file (src/commands/connection.ts:257). The new runConnectionCreate/runConnectionUpdate instead short-circuit with isJsonMode() + raw outputJson, matching only the get convention. Removing the isJsonMode() branch and calling outputSuccess alone yields both human and JSON output consistently (the new specs at src/commands/connection.spec.ts:288-302 would need to read output.data).
| outputJson(connection); | |
| return; | |
| } | |
| outputSuccess('Created connection', connection); | |
| } catch (error) { | |
| outputSuccess('Created connection', connection); |
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Fixed in 588ce9b — create/update now call outputSuccess(...) unconditionally, so JSON mode emits the standard { status: 'ok', message, data } envelope like the other resource create/update commands, and the specs assert on output.status/output.data.
| connections: { | ||
| async create(body: Record<string, unknown>) { | ||
| return workosRequest<SsoConnection>({ | ||
| method: 'POST', | ||
| path: '/connections', | ||
| apiKey: key, | ||
| baseUrl: base, | ||
| body, | ||
| }); | ||
| }, | ||
| async update(id: string, body: Record<string, unknown>) { | ||
| return workosRequest<SsoConnection>({ | ||
| method: 'PATCH', | ||
| path: `/connections/${encodeURIComponent(id)}`, | ||
| apiKey: key, | ||
| baseUrl: base, | ||
| body, | ||
| }); | ||
| }, |
There was a problem hiding this comment.
🔍 create/update return snake_case while get returns camelCase
connections.create/connections.update use the raw fetch wrapper and therefore return the API's snake_case shape (SsoConnection at src/lib/workos-client.ts:30-41), whereas runConnectionGet and runConnectionList return SDK-mapped camelCase objects (src/commands/connection.ts:220, src/commands/connection.ts:48-56). Consumers of --json output will see connection_type/organization_id from create/update but type/organizationId from get/list on the same resource. Worth confirming this is acceptable for agent tooling, or normalizing the raw response before printing.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Accurate observation. This is deliberate: the pinned @workos-inc/node (8.13.0) has no createConnection/updateConnection, so these go through the raw transport, and I kept the API's snake_case shape in the output rather than hand-rolling a camelCase mapping. It's also symmetric with the input — --data/--file bodies are authored in the API's snake_case shape (matching the API reference docs), so the response echoes the same field names. If the SDK later ships these methods, switching to it would align create/update with get/list automatically. Happy to normalize now instead if consistency across subcommands matters more for agent tooling.
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Summary
Adds
workos connection createandworkos connection update <id>for provisioning and migrating SSO connections via the Connections API, plus aconnectionsalias for the resource (kept out of metric fragmentation viacommand-aliases.ts).--data '<json>'and--file <path|->(stdin) provide the raw request body; top-level flags--org/--organization-id,--name,--external-id,--typeoverride/merge on top. Nestedsaml_options/oidc_options/attribute_mapsare passed through the raw JSON body. Non-object JSON bodies are rejected withinvalid_json_body(type-narrowed via anisJsonObjectguard — no casts).workos-api.ts: addPATCHtoWorkOSRequestOptions['method']and send JSON bodies for PATCH.workos-client.ts: newconnections.create(body)/connections.update(id, body)raw methods.connection createrequiresorganization_id;connection updaterejects an empty body. Both support human and--jsonoutput and reuse the standard API-key resolution and error handling.These endpoints are feature-gated server-side (
connections-api-migrations-capabilities-api) and return 404 unless enabled for the team.Part of https://linear.app/workos/issue/ENT-6443 — companion docs PR in workos/workos.
Test plan
bun run typecheck,bun run lint,bun run format:check,bun run build— clean.bun run vitest run src/commands/connection.spec.ts src/lib/workos-api.spec.ts— new specs cover request construction, flag/JSON precedence,--file/stdin parsing, invalid JSON, empty update body, API errors, and JSON output mode.Link to Devin session: https://app.devin.ai/sessions/9151860048f44f5084cd0fe314e8722c
Requested by: @qbalin