fix(js-sdk): forward name param in createSnapshot and return names#1263
fix(js-sdk): forward name param in createSnapshot and return names#1263Yanhu007 wants to merge 1 commit intoe2b-dev:mainfrom
Conversation
createSnapshot() sends an empty body, ignoring the name parameter
from the API. The SnapshotInfo interface also omits the names array
from the API response. This means SDK users cannot create named
snapshots.
- Add CreateSnapshotOpts with optional name field
- Forward name to POST /sandboxes/{sandboxID}/snapshots body
- Add names to SnapshotInfo interface
- Return names from both createSnapshot and list paginator
- Export CreateSnapshotOpts from package index
Fixes e2b-dev#1249
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 09370119f9
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| }, | ||
| body: {}, | ||
| body: { | ||
| ...(opts?.name && { name: opts.name }), |
There was a problem hiding this comment.
Forward empty snapshot names to API
The request body currently uses a truthy guard (opts?.name && { name: opts.name }), which drops name when it is an empty string. In that case createSnapshot({ name: '' }) is silently converted into an unnamed snapshot request instead of preserving caller intent and letting the API validate/reject the value, which can create unexpected anonymous snapshots when names come from user input. Check explicitly for undefined so every provided value is forwarded.
Useful? React with 👍 / 👎.
Summary
Fixes #1249
createSnapshot()sendsbody: {}, silently ignoring thenameparameter. TheSnapshotInfointerface also omits thenamesarray from the API response. This means SDK users cannot create named snapshots.Changes
sandboxApi.tsCreateSnapshotOpts: new interface extendingSandboxApiOptswith optionalnameSnapshotInfo: addednames: string[]fieldcreateSnapshot(): forwardsnameto request body, returnsnamesfrom responseSnapshotPaginator.nextItems(): returnsnamesfrom list responseindex.ts(sandbox)createSnapshot()to acceptCreateSnapshotOptsindex.ts(package)CreateSnapshotOptsBefore / After