@declaw/sdk 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,20 @@ All notable changes to the Declaw TypeScript / JavaScript SDK are documented in
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.1.2]
9
+
10
+ ### Fixed
11
+
12
+ - **Binary-safe `files.read`.** `sandbox.files.read(path, { format: "bytes" })`
13
+ now returns a `Uint8Array` with the raw bytes. Previously the
14
+ `format` option was silently ignored: every read went through the
15
+ `text/plain` accept path and was UTF-8 decoded, so any byte with the
16
+ high bit set collapsed to the replacement character `U+FFFD` and the
17
+ buffer came back short of the real file length. Binary writes were
18
+ already routed through `PUT /files/raw` (1.0.1); this patch closes
19
+ the read side so PNGs, compressed archives, and other non-text blobs
20
+ round-trip unmodified.
21
+
8
22
  ## [1.1.1]
9
23
 
10
24
  ### Changed
package/dist/index.cjs CHANGED
@@ -246,6 +246,12 @@ var ApiClient = class {
246
246
  async get(path, opts) {
247
247
  return this.requestWithRetry("GET", path, opts);
248
248
  }
249
+ /** Send a GET request and return the response body as raw bytes. */
250
+ async getBytes(path, opts) {
251
+ const response = await this.requestWithRetry("GET", path, opts, true);
252
+ const buf = await response.arrayBuffer();
253
+ return new Uint8Array(buf);
254
+ }
249
255
  /** Send a POST request and return parsed JSON. */
250
256
  async post(path, opts) {
251
257
  return this.requestWithRetry("POST", path, opts);
@@ -1370,15 +1376,18 @@ var Filesystem = class {
1370
1376
  this.sandboxId = sandboxId;
1371
1377
  this.client = client;
1372
1378
  }
1373
- /**
1374
- * Read a file's contents as a string.
1375
- *
1376
- * @param path - Absolute path to the file.
1377
- * @param opts - Optional user and request timeout.
1378
- * @returns The file contents as a string.
1379
- */
1380
1379
  async read(path, opts) {
1381
1380
  const user = opts?.user ?? DEFAULT_USER;
1381
+ if (opts?.format === "bytes") {
1382
+ return this.client.getBytes(
1383
+ `/sandboxes/${this.sandboxId}/files`,
1384
+ {
1385
+ params: { path, username: user },
1386
+ headers: { "Accept": "application/octet-stream" },
1387
+ timeout: opts?.requestTimeout
1388
+ }
1389
+ );
1390
+ }
1382
1391
  const result = await this.client.get(
1383
1392
  `/sandboxes/${this.sandboxId}/files`,
1384
1393
  {