fix(js-sdk): forward name param and expose names in createSnapshot#1284
fix(js-sdk): forward name param and expose names in createSnapshot#1284FisherXZ wants to merge 5 commits intoe2b-dev:mainfrom
Conversation
Adds SnapshotCreateOpts with an optional name field, threads it through to the POST body, and adds names[] to SnapshotInfo so callers can create named snapshots and read back their assigned aliases. Also fixes SnapshotPaginator.nextItems() which had the same names omission. Fixes e2b-dev#1249 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
🦋 Changeset detectedLatest commit: 283703f The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ba584c106a
ℹ️ 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 provided snapshot name without truthy filtering
Using ...(opts?.name && { name: opts.name }) drops the name field when callers pass an empty string, so createSnapshot({ name: "" }) silently behaves like an unnamed snapshot instead of letting the API validate/reject the explicit value. This makes client behavior inconsistent with user input and can create unintended unnamed snapshots; check for undefined instead of truthiness when deciding whether to include name.
Useful? React with 👍 / 👎.
Truthy check silently drops name: '' — check !== undefined instead so the API can validate/reject an explicit empty string rather than the SDK quietly omitting it. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
fe8b38b to
e4c19b2
Compare
Mirrors the JS SDK fix: adds optional name param to create_snapshot / _cls_create_snapshot in both sync and async paths, maps names[] from the API response in SnapshotInfo, and fixes the same omission in both snapshot paginators. Also exports SnapshotCreateOpts from the JS SDK public index and adds a patch changeset for both packages. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
snapshot.names / res.parsed.names is already list[str] from the generated client, so list() was an unnecessary O(n) copy. Replace with `or []` to also guard against None for snapshots created before the names field existed. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
we're working on it here |
Summary
Closes #1249.
Named snapshots let users write `Sandbox.create('team/my-snapshot')` instead of tracking raw template IDs like `abc123:default`. But passing `name` to `createSnapshot()` / `create_snapshot()` silently had no effect in both SDKs — the generated REST clients were already correct, but the hand-written wrapper layer never forwarded the value or surfaced the response field.
Three layers had the same gap in both SDKs:
JS SDK changes (`packages/js-sdk/`):
Python SDK changes (`packages/python-sdk/`):
Backwards compatible: `name` is optional everywhere, `names` defaults to `[]`.
Usage
JS:
```ts
const snap = await sandbox.createSnapshot({ name: 'my-snapshot' })
console.log(snap.snapshotId) // 'team-slug/my-snapshot:default'
console.log(snap.names) // ['team-slug/my-snapshot:default']
// Now usable by name instead of raw ID
const sbx = await Sandbox.create('team-slug/my-snapshot')
```
Python:
```python
snap = sandbox.create_snapshot(name='my-snapshot')
print(snap.snapshot_id) # 'team-slug/my-snapshot:default'
print(snap.names) # ['team-slug/my-snapshot:default']
sbx = Sandbox.create('team-slug/my-snapshot')
```
Test plan
🤖 Generated with Claude Code