ppio-sandbox 1.0.3-b1 → 1.1.1-a2

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-b1";
51
+ var version = "1.1.1-a2";
52
52
 
53
53
  // src/core/api/metadata.ts
54
54
  function getRuntime() {
@@ -1128,6 +1128,209 @@ var CommandHandle = class {
1128
1128
  }
1129
1129
  };
1130
1130
 
1131
+ // src/core/template/templateApi.ts
1132
+ var TemplateApi = class {
1133
+ constructor() {
1134
+ }
1135
+ /**
1136
+ * List templates with pagination support (user's default team only).
1137
+ *
1138
+ * @param opts template list options.
1139
+ *
1140
+ * @returns paginated template list response.
1141
+ *
1142
+ * @example
1143
+ * ```ts
1144
+ * const response = await TemplateApi.listTemplates({
1145
+ * templateType: 'snapshot_template',
1146
+ * page: 1,
1147
+ * limit: 20,
1148
+ * })
1149
+ * console.log('Total templates:', response.total)
1150
+ * console.log('Templates:', response.templates)
1151
+ * ```
1152
+ */
1153
+ static async listTemplates(opts) {
1154
+ const config = new ConnectionConfig(opts);
1155
+ const client = new ApiClient(config);
1156
+ const res = await client.api.GET("/v2/templates", {
1157
+ params: {
1158
+ query: {
1159
+ template_type: opts == null ? void 0 : opts.templateType,
1160
+ page: opts == null ? void 0 : opts.page,
1161
+ limit: opts == null ? void 0 : opts.limit
1162
+ }
1163
+ },
1164
+ signal: config.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
1165
+ });
1166
+ const err = handleApiError(res);
1167
+ if (err) {
1168
+ throw err;
1169
+ }
1170
+ if (!res.data) {
1171
+ throw new Error("Template list response data is missing");
1172
+ }
1173
+ const templates = (res.data.templates || []).map(
1174
+ (t) => ({
1175
+ templateId: t.templateID,
1176
+ aliases: t.aliases,
1177
+ buildCount: t.buildCount,
1178
+ buildId: t.buildID,
1179
+ cpuCount: t.cpuCount,
1180
+ createdAt: new Date(t.createdAt),
1181
+ createdBy: t.createdBy,
1182
+ diskSizeMB: t.diskSizeMB,
1183
+ envdVersion: t.envdVersion,
1184
+ lastSpawnedAt: new Date(t.lastSpawnedAt),
1185
+ memoryMB: t.memoryMB,
1186
+ metadata: t.metadata,
1187
+ public: t.public,
1188
+ spawnCount: t.spawnCount,
1189
+ templateType: t.templateType,
1190
+ originSandboxID: t.originSandboxID,
1191
+ updatedAt: new Date(t.updatedAt)
1192
+ })
1193
+ );
1194
+ return {
1195
+ templates,
1196
+ page: res.data.page,
1197
+ limit: res.data.limit,
1198
+ total: res.data.total,
1199
+ totalPages: res.data.totalPages
1200
+ };
1201
+ }
1202
+ /**
1203
+ * Delete a template by its ID.
1204
+ *
1205
+ * @param templateId template ID to delete.
1206
+ * @param opts API options.
1207
+ *
1208
+ * @returns `true` if the template was deleted successfully.
1209
+ *
1210
+ * @example
1211
+ * ```ts
1212
+ * await TemplateApi.deleteTemplate('template-id')
1213
+ * console.log('Template deleted successfully')
1214
+ * ```
1215
+ */
1216
+ static async deleteTemplate(templateId, opts) {
1217
+ const config = new ConnectionConfig(opts);
1218
+ const client = new ApiClient(config);
1219
+ const res = await client.api.DELETE("/templates/{templateID}", {
1220
+ params: {
1221
+ path: {
1222
+ templateID: templateId
1223
+ }
1224
+ },
1225
+ signal: config.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
1226
+ });
1227
+ const err = handleApiError(res);
1228
+ if (err) {
1229
+ throw err;
1230
+ }
1231
+ return res.response.status === 204;
1232
+ }
1233
+ };
1234
+ var TemplatePaginator = class {
1235
+ constructor(opts) {
1236
+ var _a2, _b;
1237
+ this.config = new ConnectionConfig(opts);
1238
+ this.client = new ApiClient(this.config);
1239
+ this._hasNext = true;
1240
+ this._currentPage = ((_a2 = opts == null ? void 0 : opts.page) != null ? _a2 : 1) - 1;
1241
+ this._totalPages = void 0;
1242
+ this.templateType = opts == null ? void 0 : opts.templateType;
1243
+ this.limit = (_b = opts == null ? void 0 : opts.limit) != null ? _b : 20;
1244
+ }
1245
+ /**
1246
+ * Returns true if there are more pages to fetch.
1247
+ */
1248
+ get hasNext() {
1249
+ return this._hasNext;
1250
+ }
1251
+ /**
1252
+ * Returns the current page number (1-based).
1253
+ */
1254
+ get currentPage() {
1255
+ return this._currentPage + 1;
1256
+ }
1257
+ /**
1258
+ * Returns the total number of pages (if known).
1259
+ */
1260
+ get totalPages() {
1261
+ return this._totalPages;
1262
+ }
1263
+ /**
1264
+ * Get the next page of templates.
1265
+ *
1266
+ * @throws Error if there are no more pages to fetch. Call this method only if `hasNext` is `true`.
1267
+ *
1268
+ * @returns Paginated template list response.
1269
+ */
1270
+ async nextPage() {
1271
+ if (!this.hasNext) {
1272
+ throw new Error("No more pages to fetch");
1273
+ }
1274
+ this._currentPage++;
1275
+ const res = await this.client.api.GET("/v2/templates", {
1276
+ params: {
1277
+ query: {
1278
+ template_type: this.templateType,
1279
+ page: this._currentPage + 1,
1280
+ // API expects 1-based page
1281
+ limit: this.limit
1282
+ }
1283
+ },
1284
+ signal: this.config.getSignal()
1285
+ });
1286
+ const err = handleApiError(res);
1287
+ if (err) {
1288
+ throw err;
1289
+ }
1290
+ if (!res.data) {
1291
+ throw new Error("Template list response data is missing");
1292
+ }
1293
+ this._totalPages = res.data.totalPages;
1294
+ this._hasNext = this._currentPage + 1 < res.data.totalPages;
1295
+ const templates = (res.data.templates || []).map(
1296
+ (t) => ({
1297
+ templateId: t.templateID,
1298
+ aliases: t.aliases,
1299
+ buildCount: t.buildCount,
1300
+ buildId: t.buildID,
1301
+ cpuCount: t.cpuCount,
1302
+ createdAt: new Date(t.createdAt),
1303
+ createdBy: t.createdBy,
1304
+ diskSizeMB: t.diskSizeMB,
1305
+ envdVersion: t.envdVersion,
1306
+ lastSpawnedAt: new Date(t.lastSpawnedAt),
1307
+ memoryMB: t.memoryMB,
1308
+ metadata: t.metadata,
1309
+ public: t.public,
1310
+ spawnCount: t.spawnCount,
1311
+ templateType: t.templateType,
1312
+ originSandboxID: t.originSandboxID,
1313
+ updatedAt: new Date(t.updatedAt)
1314
+ })
1315
+ );
1316
+ return {
1317
+ templates,
1318
+ page: res.data.page,
1319
+ limit: res.data.limit,
1320
+ total: res.data.total,
1321
+ totalPages: res.data.totalPages
1322
+ };
1323
+ }
1324
+ /**
1325
+ * Reset the paginator to the first page.
1326
+ */
1327
+ reset() {
1328
+ this._currentPage = 0;
1329
+ this._hasNext = true;
1330
+ this._totalPages = void 0;
1331
+ }
1332
+ };
1333
+
1131
1334
  // src/core/sandbox/index.ts
1132
1335
  import { createConnectTransport } from "@connectrpc/connect-web";
1133
1336
 
@@ -1739,7 +1942,8 @@ var SandboxApi = class {
1739
1942
  }));
1740
1943
  return {
1741
1944
  count: res.data.count,
1742
- sandboxes
1945
+ sandboxes,
1946
+ snapshotTemplateId: res.data.snapshotTemplateId
1743
1947
  };
1744
1948
  }
1745
1949
  static async createSandbox(template, timeoutMs, opts) {
@@ -1807,6 +2011,92 @@ var SandboxApi = class {
1807
2011
  }
1808
2012
  return true;
1809
2013
  }
2014
+ /**
2015
+ * Reset sandbox memory and optionally resume the sandbox.
2016
+ *
2017
+ * @param sandboxId sandbox ID.
2018
+ * @param opts reset options.
2019
+ *
2020
+ * @returns `true` if reset succeeded; `false` if conflict (no-op).
2021
+ */
2022
+ static async reset(sandboxId, opts) {
2023
+ var _a2, _b, _c;
2024
+ const config = new ConnectionConfig(opts);
2025
+ const client = new ApiClient(config);
2026
+ const res = await client.api.POST("/sandboxes/{sandboxID}/reset", {
2027
+ params: {
2028
+ path: {
2029
+ sandboxID: sandboxId
2030
+ }
2031
+ },
2032
+ body: __spreadValues({
2033
+ resume: (_a2 = opts == null ? void 0 : opts.resume) != null ? _a2 : true
2034
+ }, typeof (opts == null ? void 0 : opts.timeoutMs) === "number" ? { timeout: timeoutToSeconds(opts.timeoutMs) } : {}),
2035
+ signal: config.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
2036
+ });
2037
+ if (((_b = res.error) == null ? void 0 : _b.code) === 404) {
2038
+ throw new NotFoundError(`Sandbox ${sandboxId} not found`);
2039
+ }
2040
+ if (((_c = res.error) == null ? void 0 : _c.code) === 409) {
2041
+ return false;
2042
+ }
2043
+ const err = handleApiError(res);
2044
+ if (err) {
2045
+ throw err;
2046
+ }
2047
+ return true;
2048
+ }
2049
+ /**
2050
+ * Commit the sandbox to create a template snapshot.
2051
+ *
2052
+ * @param sandboxId sandbox ID.
2053
+ * @param opts commit options.
2054
+ *
2055
+ * @returns template information.
2056
+ */
2057
+ static async commit(sandboxId, opts) {
2058
+ var _a2;
2059
+ const config = new ConnectionConfig(opts);
2060
+ const client = new ApiClient(config);
2061
+ const res = await client.api.POST("/sandboxes/{sandboxID}/commit", {
2062
+ params: {
2063
+ path: {
2064
+ sandboxID: sandboxId
2065
+ }
2066
+ },
2067
+ body: (opts == null ? void 0 : opts.alias) ? { alias: opts.alias } : void 0,
2068
+ signal: config.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
2069
+ });
2070
+ if (((_a2 = res.error) == null ? void 0 : _a2.code) === 404) {
2071
+ throw new NotFoundError(`Sandbox ${sandboxId} not found`);
2072
+ }
2073
+ const err = handleApiError(res);
2074
+ if (err) {
2075
+ throw err;
2076
+ }
2077
+ if (!res.data) {
2078
+ throw new Error("Commit response data is missing");
2079
+ }
2080
+ return {
2081
+ templateId: res.data.templateID,
2082
+ aliases: res.data.aliases,
2083
+ buildCount: res.data.buildCount,
2084
+ buildId: res.data.buildID,
2085
+ cpuCount: res.data.cpuCount,
2086
+ createdAt: new Date(res.data.createdAt),
2087
+ createdBy: res.data.createdBy,
2088
+ diskSizeMB: res.data.diskSizeMB,
2089
+ envdVersion: res.data.envdVersion,
2090
+ lastSpawnedAt: new Date(res.data.lastSpawnedAt),
2091
+ memoryMB: res.data.memoryMB,
2092
+ metadata: res.data.metadata,
2093
+ public: res.data.public,
2094
+ spawnCount: res.data.spawnCount,
2095
+ templateType: res.data.templateType,
2096
+ originSandboxID: res.data.originSandboxID,
2097
+ updatedAt: new Date(res.data.updatedAt)
2098
+ };
2099
+ }
1810
2100
  };
1811
2101
  var SandboxPaginator = class {
1812
2102
  constructor(opts) {
@@ -2061,7 +2351,17 @@ var Sandbox = class extends SandboxApi {
2061
2351
  envdAccessToken: sb.envdAccessToken
2062
2352
  }, config));
2063
2353
  });
2064
- return instances;
2354
+ return {
2355
+ count: res.count,
2356
+ snapshotTemplateId: res.snapshotTemplateId,
2357
+ sandboxes: instances
2358
+ };
2359
+ }
2360
+ /**
2361
+ * Reset sandbox memory and optionally resume the sandbox.
2362
+ */
2363
+ static async reset(sandboxId, opts) {
2364
+ return await SandboxApi.reset(sandboxId, opts);
2065
2365
  }
2066
2366
  /**
2067
2367
  * Connect to a sandbox. If the sandbox is paused, it will be automatically resumed.
@@ -2184,6 +2484,30 @@ var Sandbox = class extends SandboxApi {
2184
2484
  async betaPause(opts) {
2185
2485
  return await SandboxApi.betaPause(this.sandboxId, opts);
2186
2486
  }
2487
+ /**
2488
+ * Reset sandbox memory and optionally resume the sandbox.
2489
+ */
2490
+ async reset(opts) {
2491
+ return await SandboxApi.reset(this.sandboxId, opts);
2492
+ }
2493
+ /**
2494
+ * Commit the sandbox to create a template snapshot.
2495
+ *
2496
+ * This creates a snapshot of the current sandbox state that can be used as a template to create new sandboxes.
2497
+ *
2498
+ * @param opts commit options including optional alias for the template.
2499
+ *
2500
+ * @returns template information.
2501
+ *
2502
+ * @example
2503
+ * ```ts
2504
+ * const template = await sandbox.commit({ alias: 'my-custom-template' })
2505
+ * console.log('Created template:', template.templateId)
2506
+ * ```
2507
+ */
2508
+ async commit(opts) {
2509
+ return await SandboxApi.commit(this.sandboxId, __spreadValues(__spreadValues({}, this.connectionConfig), opts));
2510
+ }
2187
2511
  /**
2188
2512
  * Get the URL to upload a file to the sandbox.
2189
2513
  *
@@ -2330,7 +2654,9 @@ export {
2330
2654
  FilesystemEventType,
2331
2655
  FileType2 as FileType,
2332
2656
  CommandExitError,
2657
+ TemplateApi,
2658
+ TemplatePaginator,
2333
2659
  Sandbox,
2334
2660
  core_default
2335
2661
  };
2336
- //# sourceMappingURL=chunk-MMBQNTJE.mjs.map
2662
+ //# sourceMappingURL=chunk-KU764YSO.mjs.map