freestyle-sandboxes 0.1.0 → 0.1.1

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/index.cjs CHANGED
@@ -2847,7 +2847,16 @@ class ApiClient {
2847
2847
  body: body ? JSON.stringify(body) : void 0
2848
2848
  });
2849
2849
  if (!response.ok) {
2850
- const errorData = await response.json();
2850
+ let errorText = await response.text();
2851
+ let errorData;
2852
+ try {
2853
+ errorData = JSON.parse(errorText);
2854
+ } catch (e) {
2855
+ if (response.status === 401) {
2856
+ errorText += " (Your API key or access token may be invalid.)";
2857
+ }
2858
+ throw new Error(`HTTP error ${response.status}: ${errorText}. ${e}`);
2859
+ }
2851
2860
  throw errorFromJSON(errorData);
2852
2861
  }
2853
2862
  return response.json();
@@ -4281,6 +4290,11 @@ class VmsNamespace {
4281
4290
  ref({ vmId }) {
4282
4291
  return new Vm(vmId, this.apiClient);
4283
4292
  }
4293
+ async delete({ vmId }) {
4294
+ return this.apiClient.delete("/v1/vms/{vm_id}", {
4295
+ params: { vm_id: vmId }
4296
+ });
4297
+ }
4284
4298
  }
4285
4299
  class VmTemplate {
4286
4300
  template;
@@ -4299,15 +4313,20 @@ class Freestyle {
4299
4313
  edge;
4300
4314
  vms;
4301
4315
  constructor(options = {}) {
4302
- options.baseUrl ?? process.env.FREESTYLE_API_URL;
4303
- let apiKey;
4316
+ if (!options.baseUrl) {
4317
+ options.baseUrl = process.env.FREESTYLE_API_URL;
4318
+ }
4319
+ if (options.baseUrl) {
4320
+ options.baseUrl = new URL(options.baseUrl).toString();
4321
+ options.baseUrl = options.baseUrl.replace(/\/+$/, "");
4322
+ }
4304
4323
  if ("accessToken" in options && options.accessToken) {
4305
4324
  options.accessToken;
4306
4325
  } else {
4307
- apiKey = options.apiKey ?? process.env.FREESTYLE_API_KEY;
4308
- if (!apiKey) {
4326
+ options.apiKey = options.apiKey ?? process.env.FREESTYLE_API_KEY;
4327
+ if (!options.apiKey) {
4309
4328
  throw new Error(
4310
- "API key is required. Please provide it in the constructor or set the FREESTYLE_API_KEY environment variable."
4329
+ "API key is required. Please set the FREESTYLE_API_KEY environment variable or construct a Freestyle client with the `apiKey` option."
4311
4330
  );
4312
4331
  }
4313
4332
  }
package/index.d.cts CHANGED
@@ -9370,6 +9370,9 @@ declare class VmsNamespace {
9370
9370
  ref({ vmId }: {
9371
9371
  vmId: string;
9372
9372
  }): Vm;
9373
+ delete({ vmId }: {
9374
+ vmId: string;
9375
+ }): Promise<ResponseDeleteV1VmsVmId200>;
9373
9376
  }
9374
9377
  declare class VmTemplate {
9375
9378
  private template;
package/index.d.mts CHANGED
@@ -9370,6 +9370,9 @@ declare class VmsNamespace {
9370
9370
  ref({ vmId }: {
9371
9371
  vmId: string;
9372
9372
  }): Vm;
9373
+ delete({ vmId }: {
9374
+ vmId: string;
9375
+ }): Promise<ResponseDeleteV1VmsVmId200>;
9373
9376
  }
9374
9377
  declare class VmTemplate {
9375
9378
  private template;
package/index.mjs CHANGED
@@ -2845,7 +2845,16 @@ class ApiClient {
2845
2845
  body: body ? JSON.stringify(body) : void 0
2846
2846
  });
2847
2847
  if (!response.ok) {
2848
- const errorData = await response.json();
2848
+ let errorText = await response.text();
2849
+ let errorData;
2850
+ try {
2851
+ errorData = JSON.parse(errorText);
2852
+ } catch (e) {
2853
+ if (response.status === 401) {
2854
+ errorText += " (Your API key or access token may be invalid.)";
2855
+ }
2856
+ throw new Error(`HTTP error ${response.status}: ${errorText}. ${e}`);
2857
+ }
2849
2858
  throw errorFromJSON(errorData);
2850
2859
  }
2851
2860
  return response.json();
@@ -4279,6 +4288,11 @@ class VmsNamespace {
4279
4288
  ref({ vmId }) {
4280
4289
  return new Vm(vmId, this.apiClient);
4281
4290
  }
4291
+ async delete({ vmId }) {
4292
+ return this.apiClient.delete("/v1/vms/{vm_id}", {
4293
+ params: { vm_id: vmId }
4294
+ });
4295
+ }
4282
4296
  }
4283
4297
  class VmTemplate {
4284
4298
  template;
@@ -4297,15 +4311,20 @@ class Freestyle {
4297
4311
  edge;
4298
4312
  vms;
4299
4313
  constructor(options = {}) {
4300
- options.baseUrl ?? process.env.FREESTYLE_API_URL;
4301
- let apiKey;
4314
+ if (!options.baseUrl) {
4315
+ options.baseUrl = process.env.FREESTYLE_API_URL;
4316
+ }
4317
+ if (options.baseUrl) {
4318
+ options.baseUrl = new URL(options.baseUrl).toString();
4319
+ options.baseUrl = options.baseUrl.replace(/\/+$/, "");
4320
+ }
4302
4321
  if ("accessToken" in options && options.accessToken) {
4303
4322
  options.accessToken;
4304
4323
  } else {
4305
- apiKey = options.apiKey ?? process.env.FREESTYLE_API_KEY;
4306
- if (!apiKey) {
4324
+ options.apiKey = options.apiKey ?? process.env.FREESTYLE_API_KEY;
4325
+ if (!options.apiKey) {
4307
4326
  throw new Error(
4308
- "API key is required. Please provide it in the constructor or set the FREESTYLE_API_KEY environment variable."
4327
+ "API key is required. Please set the FREESTYLE_API_KEY environment variable or construct a Freestyle client with the `apiKey` option."
4309
4328
  );
4310
4329
  }
4311
4330
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "freestyle-sandboxes",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "require": {