ppio-sandbox 1.0.3-a7 → 1.0.3

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.
@@ -48,7 +48,7 @@ import createClient from "openapi-fetch";
48
48
  import platform from "platform";
49
49
 
50
50
  // package.json
51
- var version = "1.0.3-a7";
51
+ var version = "1.0.3";
52
52
 
53
53
  // src/core/api/metadata.ts
54
54
  function getRuntime() {
@@ -258,7 +258,6 @@ var ApiClient = class {
258
258
 
259
259
  // src/core/connectionConfig.ts
260
260
  var REQUEST_TIMEOUT_MS = 6e4;
261
- var REQUEST_LONG_TIMEOUT_MS = 3e5;
262
261
  var DEFAULT_SANDBOX_TIMEOUT_MS = 3e5;
263
262
  var KEEPALIVE_PING_INTERVAL_SEC = 50;
264
263
  var KEEPALIVE_PING_HEADER = "Keepalive-Ping-Interval";
@@ -628,6 +627,9 @@ var Filesystem2 = class {
628
627
  return new Uint8Array(res.data);
629
628
  }
630
629
  if (res.response.headers.get("content-length") === "0") {
630
+ if (format === "blob") {
631
+ return new Blob([]);
632
+ }
631
633
  return "";
632
634
  }
633
635
  return res.data;
@@ -1666,7 +1668,7 @@ var SandboxApi = class {
1666
1668
  * @returns `true` if the sandbox got paused, `false` if the sandbox was already paused.
1667
1669
  */
1668
1670
  static async betaPause(sandboxId, opts) {
1669
- var _a2, _b, _c;
1671
+ var _a2, _b;
1670
1672
  const config = new ConnectionConfig(opts);
1671
1673
  const client = new ApiClient(config);
1672
1674
  const res = await client.api.POST("/sandboxes/{sandboxID}/pause", {
@@ -1675,15 +1677,12 @@ var SandboxApi = class {
1675
1677
  sandboxID: sandboxId
1676
1678
  }
1677
1679
  },
1678
- body: {
1679
- sync: (_a2 = opts == null ? void 0 : opts.sync) != null ? _a2 : false
1680
- },
1681
1680
  signal: config.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
1682
1681
  });
1683
- if (((_b = res.error) == null ? void 0 : _b.code) === 404) {
1682
+ if (((_a2 = res.error) == null ? void 0 : _a2.code) === 404) {
1684
1683
  throw new NotFoundError(`Sandbox ${sandboxId} not found`);
1685
1684
  }
1686
- if (((_c = res.error) == null ? void 0 : _c.code) === 409) {
1685
+ if (((_b = res.error) == null ? void 0 : _b.code) === 409) {
1687
1686
  return false;
1688
1687
  }
1689
1688
  const err = handleApiError(res);
@@ -1692,56 +1691,6 @@ var SandboxApi = class {
1692
1691
  }
1693
1692
  return true;
1694
1693
  }
1695
- /**
1696
- * Clone a sandbox to create multiple identical sandboxes.
1697
- *
1698
- * Note: This low-level API returns raw identifiers required to construct SDK instances.
1699
- *
1700
- * @param sandboxId sandbox ID.
1701
- * @param opts clone options including count.
1702
- *
1703
- * @returns clone response with count and list of cloned sandboxes.
1704
- */
1705
- static async cloneSandboxes(sandboxId, opts) {
1706
- var _a2, _b, _c, _d;
1707
- const config = new ConnectionConfig(opts);
1708
- const client = new ApiClient(config);
1709
- const res = await client.api.POST("/sandboxes/{sandboxID}/clone", {
1710
- params: {
1711
- path: {
1712
- sandboxID: sandboxId
1713
- }
1714
- },
1715
- body: __spreadValues({
1716
- count: (_a2 = opts.count) != null ? _a2 : 1,
1717
- nodeID: opts.nodeID,
1718
- strict: (_b = opts.strict) != null ? _b : false
1719
- }, typeof opts.timeoutMs === "number" ? { timeout: timeoutToSeconds(opts.timeoutMs) } : {}),
1720
- // Use an extended timeout for clone operation by default
1721
- signal: config.getSignal(
1722
- (_c = opts == null ? void 0 : opts.requestTimeoutMs) != null ? _c : REQUEST_LONG_TIMEOUT_MS
1723
- )
1724
- });
1725
- if (((_d = res.error) == null ? void 0 : _d.code) === 404) {
1726
- throw new NotFoundError(`Sandbox ${sandboxId} not found`);
1727
- }
1728
- const err = handleApiError(res);
1729
- if (err) {
1730
- throw err;
1731
- }
1732
- if (!res.data) {
1733
- throw new Error("Clone response data is missing");
1734
- }
1735
- const sandboxes = (res.data.sandboxes || []).map((sb) => ({
1736
- sandboxId: `${sb.sandboxID}-${sb.clientID}`,
1737
- envdVersion: sb.envdVersion,
1738
- envdAccessToken: sb.envdAccessToken
1739
- }));
1740
- return {
1741
- count: res.data.count,
1742
- sandboxes
1743
- };
1744
- }
1745
1694
  static async createSandbox(template, timeoutMs, opts) {
1746
1695
  var _a2, _b;
1747
1696
  const config = new ConnectionConfig(opts);
@@ -1755,8 +1704,7 @@ var SandboxApi = class {
1755
1704
  timeout: timeoutToSeconds(timeoutMs),
1756
1705
  secure: (_b = opts == null ? void 0 : opts.secure) != null ? _b : false,
1757
1706
  // allow_internet_access: opts?.allowInternetAccess ?? true,
1758
- allow_internet_access: true,
1759
- nodeID: opts == null ? void 0 : opts.nodeID
1707
+ allow_internet_access: true
1760
1708
  },
1761
1709
  signal: config.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
1762
1710
  });
@@ -1807,40 +1755,38 @@ var SandboxApi = class {
1807
1755
  }
1808
1756
  return true;
1809
1757
  }
1810
- /**
1811
- * Reset sandbox memory and optionally resume the sandbox.
1812
- *
1813
- * @param sandboxId sandbox ID.
1814
- * @param opts reset options.
1815
- *
1816
- * @returns `true` if reset succeeded; `false` if conflict (no-op).
1817
- */
1818
- static async reset(sandboxId, opts) {
1819
- var _a2, _b, _c;
1758
+ static async connectSandbox(sandboxId, opts) {
1759
+ var _a2, _b;
1760
+ const timeoutMs = (_a2 = opts == null ? void 0 : opts.timeoutMs) != null ? _a2 : DEFAULT_SANDBOX_TIMEOUT_MS;
1820
1761
  const config = new ConnectionConfig(opts);
1821
1762
  const client = new ApiClient(config);
1822
- const res = await client.api.POST("/sandboxes/{sandboxID}/reset", {
1763
+ const res = await client.api.POST("/sandboxes/{sandboxID}/connect", {
1823
1764
  params: {
1824
1765
  path: {
1825
1766
  sandboxID: sandboxId
1826
1767
  }
1827
1768
  },
1828
- body: __spreadValues({
1829
- resume: (_a2 = opts == null ? void 0 : opts.resume) != null ? _a2 : true
1830
- }, typeof (opts == null ? void 0 : opts.timeoutMs) === "number" ? { timeout: timeoutToSeconds(opts.timeoutMs) } : {}),
1769
+ body: {
1770
+ timeout: timeoutToSeconds(timeoutMs)
1771
+ },
1831
1772
  signal: config.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
1832
1773
  });
1833
1774
  if (((_b = res.error) == null ? void 0 : _b.code) === 404) {
1834
1775
  throw new NotFoundError(`Sandbox ${sandboxId} not found`);
1835
1776
  }
1836
- if (((_c = res.error) == null ? void 0 : _c.code) === 409) {
1837
- return false;
1838
- }
1839
1777
  const err = handleApiError(res);
1840
1778
  if (err) {
1841
1779
  throw err;
1842
1780
  }
1843
- return true;
1781
+ if (!res.data) {
1782
+ throw new Error("Sandbox not found");
1783
+ }
1784
+ return {
1785
+ sandboxId: `${res.data.sandboxID}-${res.data.clientID}`,
1786
+ envdVersion: res.data.envdVersion,
1787
+ envdAccessToken: res.data.envdAccessToken,
1788
+ sandboxDomain: void 0
1789
+ };
1844
1790
  }
1845
1791
  };
1846
1792
  var SandboxPaginator = class {
@@ -2046,64 +1992,15 @@ var Sandbox = class extends SandboxApi {
2046
1992
  * ```
2047
1993
  */
2048
1994
  static async connect(sandboxId, opts) {
2049
- try {
2050
- await SandboxApi.setTimeout(
2051
- sandboxId,
2052
- (opts == null ? void 0 : opts.timeoutMs) || DEFAULT_SANDBOX_TIMEOUT_MS,
2053
- opts
2054
- );
2055
- } catch (e) {
2056
- if (e instanceof SandboxError) {
2057
- await SandboxApi.resumeSandbox(sandboxId, opts);
2058
- } else {
2059
- throw e;
2060
- }
2061
- }
2062
- const info = await SandboxApi.getFullInfo(sandboxId, opts);
1995
+ const info = await SandboxApi.connectSandbox(sandboxId, opts);
2063
1996
  const config = new ConnectionConfig(opts);
2064
1997
  return new this(__spreadValues({
2065
- sandboxId,
1998
+ sandboxId: info.sandboxId,
2066
1999
  sandboxDomain: info.sandboxDomain,
2067
2000
  envdAccessToken: info.envdAccessToken,
2068
2001
  envdVersion: info.envdVersion
2069
2002
  }, config));
2070
2003
  }
2071
- /**
2072
- * Clone a sandbox to create multiple identical sandboxes.
2073
- *
2074
- * @param sandboxId sandbox ID.
2075
- * @param count number of sandboxes to clone.
2076
- * @param opts clone options.
2077
- *
2078
- * @returns clone response with count and list of cloned sandboxes.
2079
- *
2080
- * @example
2081
- * ```ts
2082
- * const cloneResponse = await Sandbox.clone('sandbox-id', {
2083
- * count: 3,
2084
- * strict: false
2085
- * })
2086
- * console.log(`Cloned ${cloneResponse.count} sandboxes`)
2087
- * ```
2088
- */
2089
- static async clone(sandboxId, opts) {
2090
- const res = await SandboxApi.cloneSandboxes(sandboxId, opts);
2091
- const instances = res.sandboxes.map((sb) => {
2092
- const config = new ConnectionConfig(opts);
2093
- return new this(__spreadValues({
2094
- sandboxId: sb.sandboxId,
2095
- envdVersion: sb.envdVersion,
2096
- envdAccessToken: sb.envdAccessToken
2097
- }, config));
2098
- });
2099
- return instances;
2100
- }
2101
- /**
2102
- * Reset sandbox memory and optionally resume the sandbox.
2103
- */
2104
- static async reset(sandboxId, opts) {
2105
- return await SandboxApi.reset(sandboxId, opts);
2106
- }
2107
2004
  /**
2108
2005
  * Connect to a sandbox. If the sandbox is paused, it will be automatically resumed.
2109
2006
  * Sandbox must be either running or be paused.
@@ -2124,15 +2021,7 @@ var Sandbox = class extends SandboxApi {
2124
2021
  * ```
2125
2022
  */
2126
2023
  async connect(opts) {
2127
- try {
2128
- await SandboxApi.setTimeout(
2129
- this.sandboxId,
2130
- (opts == null ? void 0 : opts.timeoutMs) || DEFAULT_SANDBOX_TIMEOUT_MS,
2131
- opts
2132
- );
2133
- } catch (e) {
2134
- await SandboxApi.resumeSandbox(this.sandboxId, opts);
2135
- }
2024
+ await SandboxApi.connectSandbox(this.sandboxId, opts);
2136
2025
  return this;
2137
2026
  }
2138
2027
  /**
@@ -2225,12 +2114,6 @@ var Sandbox = class extends SandboxApi {
2225
2114
  async betaPause(opts) {
2226
2115
  return await SandboxApi.betaPause(this.sandboxId, opts);
2227
2116
  }
2228
- /**
2229
- * Reset sandbox memory and optionally resume the sandbox.
2230
- */
2231
- async reset(opts) {
2232
- return await SandboxApi.reset(this.sandboxId, opts);
2233
- }
2234
2117
  /**
2235
2118
  * Get the URL to upload a file to the sandbox.
2236
2119
  *
@@ -2380,4 +2263,4 @@ export {
2380
2263
  Sandbox,
2381
2264
  core_default
2382
2265
  };
2383
- //# sourceMappingURL=chunk-NKWYMN2L.mjs.map
2266
+ //# sourceMappingURL=chunk-XBFDVBYI.mjs.map