Skip to content

feat(typescript): [DRAFT] creating websocket util files #7508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

lukeocodes
Copy link
Contributor

@lukeocodes lukeocodes commented Jun 13, 2025

Description

This PR adds utility functions to the generated TS SDK, improving WebSocket support in different runtimes (specifically the browser).

TODOs:

  • Generates the utils whether web sockets are required or not
  • probably more ...

New Utility Functions Added:

🔌 WebSocket Support

  • createWebSocket(url, options) - Creates WebSocket connections with runtime-specific handling:
    • Browser/Web Worker/Deno/Bun: Uses native WebSocket with auth protocols
    • Node.js: Dynamically imports ws library with proper headers
    • Unsupported runtimes: Throws descriptive error messages

🔐 Authentication Utilities

  • getAuthHeaders(apiKey) - Generates authorization headers with token format
  • getAuthProtocols(apiKey) - Creates WebSocket auth protocols array

📋 SDK Headers Management

  • getHeaders() - Provides standardized SDK headers with runtime detection:
    • User-Agent, X-Fern-Language, X-Fern-SDK-Name/Version
    • X-Fern-Runtime and X-Fern-Runtime-Version
    • CORS-aware: Returns empty object for CORS-sensitive runtimes

Testing

  • Unit tests added/updated
  • Manual testing completed

@lukeocodes lukeocodes changed the title feat(websockets): [DRAFT] creating websocket util files feat(typescript): [DRAFT] creating websocket util files Jun 13, 2025
@@ -777,6 +777,11 @@ export class GeneratedSdkClientClassImpl implements GeneratedSdkClientClass {
}

if (this.generatedWebsocketImplementation != null) {
// we need to import the factory for the client
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not certain this is how to import this from here.

@lukeocodes lukeocodes marked this pull request as ready for review June 17, 2025 12:50
@lukeocodes lukeocodes requested a review from dsinghvi as a code owner June 17, 2025 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant