freestyle-sandboxes 0.0.49 → 0.0.51

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "freestyle-sandboxes",
3
- "version": "0.0.49",
3
+ "version": "0.0.51",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -106,4 +106,4 @@
106
106
  "zod": "^3.24.1"
107
107
  },
108
108
  "packageManager": "pnpm@9.11.0+sha512.0a203ffaed5a3f63242cd064c8fb5892366c103e328079318f78062f24ea8c9d50bc6a47aa3567cabefd824d170e78fa2745ed1f16b132e16436146b7688f19b"
109
- }
109
+ }
package/src/index.ts CHANGED
@@ -29,12 +29,10 @@ import type {
29
29
  HandleVerifyDomainResponse,
30
30
  ListGitTokensResponseSuccess,
31
31
  ListPermissionResponseSuccess,
32
- BuildOptions,
33
32
  } from "../openapi/index.ts";
34
33
 
35
34
  export type {
36
35
  AccessLevel,
37
- BuildOptions,
38
36
  CreatedToken,
39
37
  CreateRepositoryResponseSuccess,
40
38
  DescribePermissionResponseSuccess,
@@ -61,6 +59,7 @@ export type {
61
59
  HandleVerifyDomainResponse,
62
60
  ListGitTokensResponseSuccess,
63
61
  ListPermissionResponseSuccess,
62
+ DeploymentBuildOptions,
64
63
  } from "../openapi/index.ts";
65
64
 
66
65
  export class FreestyleSandboxes {
@@ -107,7 +106,7 @@ export class FreestyleSandboxes {
107
106
  */
108
107
  async executeScript(
109
108
  script: string,
110
- config?: FreestyleExecuteScriptParamsConfiguration,
109
+ config?: FreestyleExecuteScriptParamsConfiguration
111
110
  ): Promise<FreestyleExecuteScriptResultSuccess> {
112
111
  const response = await sandbox_openapi.handleExecuteScript({
113
112
  client: this.client,
@@ -122,7 +121,7 @@ export class FreestyleSandboxes {
122
121
  }
123
122
  throw {
124
123
  message: `Failed to execute script: \n\n${script}\n\nError:\n\n${JSON.stringify(
125
- response,
124
+ response
126
125
  )}`,
127
126
  error: response.error,
128
127
  };
@@ -136,18 +135,8 @@ export class FreestyleSandboxes {
136
135
  */
137
136
  async deployWeb(
138
137
  source: sandbox_openapi.DeploymentSource,
139
- config?: Omit<FreestyleDeployWebConfiguration, "build"> & {
140
- build?:
141
- | BuildOptions
142
- | (Omit<BuildOptions, "command"> & {
143
- command: string | string[];
144
- });
145
- },
138
+ config?: FreestyleDeployWebConfiguration
146
139
  ): Promise<FreestyleDeployWebSuccessResponseV2> {
147
- if (Array.isArray(config.build?.command)) {
148
- config.build.command = config.build.command.join(" && ") as string;
149
- }
150
-
151
140
  const response = await sandbox_openapi.handleDeployWebV2({
152
141
  client: this.client,
153
142
  body: {
@@ -159,7 +148,7 @@ export class FreestyleSandboxes {
159
148
  return response.data;
160
149
  }
161
150
  throw new Error(
162
- `Failed to deploy web project\n\nStatus: ${response.response.status}\n\nMessage: ${response.error?.message}`,
151
+ `Failed to deploy web project\n\nStatus: ${response.response.status}\n\nMessage: ${response.error?.message}`
163
152
  );
164
153
  }
165
154
 
@@ -167,7 +156,7 @@ export class FreestyleSandboxes {
167
156
  * Deploy a Cloudstate project to a sandbox.
168
157
  */
169
158
  async deployCloudstate(
170
- body: FreestyleCloudstateDeployRequest,
159
+ body: FreestyleCloudstateDeployRequest
171
160
  ): Promise<FreestyleCloudstateDeploySuccessResponse> {
172
161
  const response = await sandbox_openapi.handleDeployCloudstate({
173
162
  client: this.client,
@@ -230,7 +219,7 @@ export class FreestyleSandboxes {
230
219
  * @returns The domain verification token.
231
220
  */
232
221
  async createDomainVerificationRequest(
233
- domain: string,
222
+ domain: string
234
223
  ): Promise<HandleCreateDomainVerificationResponse> {
235
224
  const response = await sandbox_openapi.handleCreateDomainVerification({
236
225
  client: this.client,
@@ -251,7 +240,7 @@ export class FreestyleSandboxes {
251
240
  * @returns The domain verification request.
252
241
  */
253
242
  async verifyDomain(
254
- domain: string,
243
+ domain: string
255
244
  ): Promise<HandleVerifyDomainResponse | HandleVerifyDomainError> {
256
245
  const response = await sandbox_openapi.handleVerifyDomain({
257
246
  client: this.client,
@@ -263,7 +252,7 @@ export class FreestyleSandboxes {
263
252
  return response.data;
264
253
  }
265
254
  throw new Error(
266
- `Failed to verify domain ${domain}: ${response.error.message}`,
255
+ `Failed to verify domain ${domain}: ${response.error.message}`
267
256
  );
268
257
  }
269
258
 
@@ -282,20 +271,20 @@ export class FreestyleSandboxes {
282
271
  const response = await sandbox_openapi.handleListDomainVerificationRequests(
283
272
  {
284
273
  client: this.client,
285
- },
274
+ }
286
275
  );
287
276
  if (response.data) {
288
277
  return response.data;
289
278
  }
290
279
 
291
280
  throw new Error(
292
- `Failed to list domain verification requests\n${response.error.message}`,
281
+ `Failed to list domain verification requests\n${response.error.message}`
293
282
  );
294
283
  }
295
284
 
296
285
  async deleteDomainVerificationRequest(
297
286
  domain: string,
298
- verificationCode: string,
287
+ verificationCode: string
299
288
  ): Promise<HandleDeleteDomainVerificationResponse> {
300
289
  const response = await sandbox_openapi.handleDeleteDomainVerification({
301
290
  client: this.client,
@@ -309,13 +298,13 @@ export class FreestyleSandboxes {
309
298
  }
310
299
 
311
300
  throw new Error(
312
- `Failed to delete domain verification request for domain ${domain}: ${response.error.message}`,
301
+ `Failed to delete domain verification request for domain ${domain}: ${response.error.message}`
313
302
  );
314
303
  }
315
304
 
316
305
  async listWebDeployments(
317
306
  limit?: number,
318
- offset?: number,
307
+ offset?: number
319
308
  ): Promise<HandleListWebDeploysResponse> {
320
309
  const response = await sandbox_openapi.handleListWebDeploys({
321
310
  client: this.client,
@@ -330,13 +319,13 @@ export class FreestyleSandboxes {
330
319
  }
331
320
 
332
321
  throw new Error(
333
- `Failed to list web deployments\n${response.error.message}`,
322
+ `Failed to list web deployments\n${response.error.message}`
334
323
  );
335
324
  }
336
325
 
337
326
  async listExecuteRuns(
338
327
  limit?: number,
339
- offset?: number,
328
+ offset?: number
340
329
  ): Promise<HandleListExecuteRunsResponse> {
341
330
  const response = await sandbox_openapi.handleListExecuteRuns({
342
331
  client: this.client,
@@ -364,7 +353,7 @@ export class FreestyleSandboxes {
364
353
  }
365
354
 
366
355
  throw new Error(
367
- `Failed to get execute run with ID ${id}: ${response.error.message}`,
356
+ `Failed to get execute run with ID ${id}: ${response.error.message}`
368
357
  );
369
358
  }
370
359
 
@@ -382,7 +371,7 @@ export class FreestyleSandboxes {
382
371
  }
383
372
 
384
373
  throw new Error(
385
- `Failed to provision wildcard for domain ${domain}: ${response.error.message}`,
374
+ `Failed to provision wildcard for domain ${domain}: ${response.error.message}`
386
375
  );
387
376
  }
388
377
 
@@ -417,7 +406,7 @@ export class FreestyleSandboxes {
417
406
  }
418
407
 
419
408
  throw new Error(
420
- `Failed to create git repository ${name}: ${response.error}`,
409
+ `Failed to create git repository ${name}: ${response.error}`
421
410
  );
422
411
  }
423
412
 
@@ -466,7 +455,7 @@ export class FreestyleSandboxes {
466
455
  }
467
456
 
468
457
  throw new Error(
469
- `Failed to delete git repository ${repoId}: ${response.error}`,
458
+ `Failed to delete git repository ${repoId}: ${response.error}`
470
459
  );
471
460
  }
472
461
 
@@ -535,7 +524,7 @@ export class FreestyleSandboxes {
535
524
  }
536
525
 
537
526
  throw new Error(
538
- `Failed to grant access to git identity ${identityId} for repository ${repoId}: ${response.error}`,
527
+ `Failed to grant access to git identity ${identityId} for repository ${repoId}: ${response.error}`
539
528
  );
540
529
  }
541
530
 
@@ -567,7 +556,7 @@ export class FreestyleSandboxes {
567
556
  }
568
557
 
569
558
  throw new Error(
570
- `Failed to update permission for git identity ${identityId} for repository ${repoId}: ${response.error}`,
559
+ `Failed to update permission for git identity ${identityId} for repository ${repoId}: ${response.error}`
571
560
  );
572
561
  }
573
562
 
@@ -594,7 +583,7 @@ export class FreestyleSandboxes {
594
583
  }
595
584
 
596
585
  throw new Error(
597
- `Failed to revoke access to git identity ${identityId} for repository ${repoId}: ${response.error}`,
586
+ `Failed to revoke access to git identity ${identityId} for repository ${repoId}: ${response.error}`
598
587
  );
599
588
  }
600
589
 
@@ -618,7 +607,7 @@ export class FreestyleSandboxes {
618
607
  }
619
608
 
620
609
  throw new Error(
621
- `Failed to list permissions for git identity ${identityId}: ${response.error}`,
610
+ `Failed to list permissions for git identity ${identityId}: ${response.error}`
622
611
  );
623
612
  }
624
613
 
@@ -645,7 +634,7 @@ export class FreestyleSandboxes {
645
634
  }
646
635
 
647
636
  throw new Error(
648
- `Failed to get permission for git identity ${identityId} on repository ${repoId}: ${response.error}`,
637
+ `Failed to get permission for git identity ${identityId} on repository ${repoId}: ${response.error}`
649
638
  );
650
639
  }
651
640
 
@@ -669,7 +658,7 @@ export class FreestyleSandboxes {
669
658
  }
670
659
 
671
660
  throw new Error(
672
- `Failed to create git access token: ${response.error.message}`,
661
+ `Failed to create git access token: ${response.error.message}`
673
662
  );
674
663
  }
675
664
 
@@ -698,7 +687,7 @@ export class FreestyleSandboxes {
698
687
  }
699
688
 
700
689
  throw new Error(
701
- `Failed to revoke git access token ${tokenId}: ${response.error.message}`,
690
+ `Failed to revoke git access token ${tokenId}: ${response.error.message}`
702
691
  );
703
692
  }
704
693
 
@@ -722,7 +711,7 @@ export class FreestyleSandboxes {
722
711
  }
723
712
 
724
713
  throw new Error(
725
- `Failed to list git access tokens: ${response.error.message}`,
714
+ `Failed to list git access tokens: ${response.error.message}`
726
715
  );
727
716
  }
728
717
 
@@ -746,7 +735,7 @@ export class FreestyleSandboxes {
746
735
  }
747
736
 
748
737
  throw new Error(
749
- `Failed to list git triggers for repository ${repoId}: ${response.error.message}`,
738
+ `Failed to list git triggers for repository ${repoId}: ${response.error.message}`
750
739
  );
751
740
  }
752
741
 
@@ -778,7 +767,7 @@ export class FreestyleSandboxes {
778
767
  }
779
768
 
780
769
  throw new Error(
781
- `Failed to create git trigger for repository ${repoId}: ${response.error.message}`,
770
+ `Failed to create git trigger for repository ${repoId}: ${response.error.message}`
782
771
  );
783
772
  }
784
773
 
@@ -798,7 +787,7 @@ export class FreestyleSandboxes {
798
787
  }
799
788
 
800
789
  throw new Error(
801
- `Failed to delete git trigger ${triggerId}: ${response.error.message}`,
790
+ `Failed to delete git trigger ${triggerId}: ${response.error.message}`
802
791
  );
803
792
  }
804
793
 
@@ -808,10 +797,7 @@ export class FreestyleSandboxes {
808
797
  * ephemeral so you should call this function every time you need a url. Do
809
798
  * not store the url in your database!
810
799
  */
811
- async requestDevServer({
812
- repoUrl
813
- }: { repoUrl: string }) {
814
-
800
+ async requestDevServer(repo: { repoId: string } | { repoUrl: string }) {
815
801
  function formatHook(serverUrl: string, repoUrl: string) {
816
802
  const hook =
817
803
  serverUrl +
@@ -822,37 +808,49 @@ export class FreestyleSandboxes {
822
808
  return hook;
823
809
  }
824
810
 
811
+ let repoId: string;
812
+ if ("repoId" in repo) {
813
+ repoId = repo.repoId;
814
+ } else if ("repoUrl" in repo) {
815
+ const parts = repo.repoUrl.split("/");
816
+ repoId = parts[parts.length - 1]; // Get the last part of the URL path
817
+ }
818
+
819
+ const repoUrl = process.env.GIT_URL ?? "https://git.freestyle.sh/" + repoId;
825
820
 
826
821
  const response = await sandbox_openapi.handleEphemeralDevServer({
827
822
  client: this.client,
828
823
  body: {
829
- repo: repoUrl
830
- }
824
+ repoId: repoId,
825
+ },
831
826
  });
832
827
 
833
-
834
828
  if (response.data.isNew) {
835
- const repoId = repoUrl.split("/").at(-1)!;
836
-
837
829
  await this.createGitTrigger({
838
830
  repoId: repoId,
839
831
  action: {
840
832
  endpoint: formatHook(response.data?.url!, repoUrl),
841
- action: "webhook"
833
+ action: "webhook",
842
834
  },
843
835
  trigger: {
844
836
  event: "push",
845
- }
837
+ },
846
838
  }).then(console.log);
847
839
  }
848
840
 
849
841
  if (!response.data) {
850
- throw new Error(
851
- `Failed to request dev server: ${response.error}`,
852
- )
842
+ throw new Error(`Failed to request dev server: ${response.error}`);
853
843
  }
854
844
 
855
- return response.data;
845
+ return {
846
+ ...response.data,
847
+ // @ts-ignore
848
+ mcpEphemeralUrl:
849
+ (response.data as unknown as Record<string, unknown>).mcpEphemeralUrl ||
850
+ response.data.url + "/mcp",
851
+ // @ts-ignore
852
+ ephemeralUrl: response.data.ephemeralUrl ?? response.data.url,
853
+ };
856
854
  }
857
855
  }
858
856