fix(sdk): handle nullable unions and browser headers#4722
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughThe TypeScript/Zod emitter now models nullable unions with ChangesSDK schema and runtime behavior
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| if ( | ||
| typeof process !== 'undefined' && | ||
| process.versions?.node != null && | ||
| !request.headers.has('User-Agent') | ||
| ) { | ||
| request.headers.set('User-Agent', `openmeter-node/${SDK_VERSION}`) |
There was a problem hiding this comment.
Polyfilled Process Triggers Browser Header
A browser bundle that provides a Node-compatible process.versions.node value passes this check even though requests are still subject to CORS. The SDK then adds User-Agent, causing an otherwise simple cross-origin request to preflight and potentially fail; the browser tests only cover an undefined process, not this common polyfilled state.
Context Used: api/spec/AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: api/spec/packages/typespec-typescript/templates/runtime/core.ts
Line: 34-39
Comment:
**Polyfilled Process Triggers Browser Header**
A browser bundle that provides a Node-compatible `process.versions.node` value passes this check even though requests are still subject to CORS. The SDK then adds `User-Agent`, causing an otherwise simple cross-origin request to preflight and potentially fail; the browser tests only cover an undefined `process`, not this common polyfilled state.
**Context Used:** api/spec/AGENTS.md ([source](https://app.greptile.com/openmeter/github/openmeterio/openmeter/-/custom-context?memory=28ba6068-00f9-4629-9b78-8e49cc802858))
How can I resolve this? If you propose a fix, please make it concise.
Summary by CodeRabbit
User-Agentheaders from being added in browser and worker environments.User-Agentvalues across supported environments.Greptile Summary
This PR improves nullable-union emission and avoids browser telemetry headers. The main changes are:
.nullable()wrapper.User-Agentto detected Node runtimes.Confidence Score: 5/5
The changed flow looks mergeable after hardening browser runtime detection.
processis absent.api/spec/packages/typespec-typescript/templates/runtime/core.ts
Important Files Changed
Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix(sdk): handle nullable unions and bro..." | Re-trigger Greptile
Context used (3)