freestyle-sandboxes 0.0.47 → 0.0.49

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/dist/index.cjs CHANGED
@@ -783,12 +783,30 @@ ${response.error.message}`);
783
783
  async requestDevServer({
784
784
  repoUrl
785
785
  }) {
786
+ function formatHook(serverUrl, repoUrl2) {
787
+ const hook = serverUrl + "/__freestyle_dev_server/update/git?repo=" + encodeURIComponent(repoUrl2);
788
+ console.log(hook);
789
+ return hook;
790
+ }
786
791
  const response = await handleEphemeralDevServer({
787
792
  client: this.client,
788
793
  body: {
789
794
  repo: repoUrl
790
795
  }
791
796
  });
797
+ if (response.data.isNew) {
798
+ const repoId = repoUrl.split("/").at(-1);
799
+ await this.createGitTrigger({
800
+ repoId,
801
+ action: {
802
+ endpoint: formatHook(response.data?.url, repoUrl),
803
+ action: "webhook"
804
+ },
805
+ trigger: {
806
+ event: "push"
807
+ }
808
+ }).then(console.log);
809
+ }
792
810
  if (!response.data) {
793
811
  throw new Error(
794
812
  `Failed to request dev server: ${response.error}`
package/dist/index.mjs CHANGED
@@ -781,12 +781,30 @@ ${response.error.message}`);
781
781
  async requestDevServer({
782
782
  repoUrl
783
783
  }) {
784
+ function formatHook(serverUrl, repoUrl2) {
785
+ const hook = serverUrl + "/__freestyle_dev_server/update/git?repo=" + encodeURIComponent(repoUrl2);
786
+ console.log(hook);
787
+ return hook;
788
+ }
784
789
  const response = await handleEphemeralDevServer({
785
790
  client: this.client,
786
791
  body: {
787
792
  repo: repoUrl
788
793
  }
789
794
  });
795
+ if (response.data.isNew) {
796
+ const repoId = repoUrl.split("/").at(-1);
797
+ await this.createGitTrigger({
798
+ repoId,
799
+ action: {
800
+ endpoint: formatHook(response.data?.url, repoUrl),
801
+ action: "webhook"
802
+ },
803
+ trigger: {
804
+ event: "push"
805
+ }
806
+ }).then(console.log);
807
+ }
790
808
  if (!response.data) {
791
809
  throw new Error(
792
810
  `Failed to request dev server: ${response.error}`
@@ -51,6 +51,16 @@ function FreestyleDevServerInner({
51
51
  queryFn: async () => await requestDevServer({ repoUrl }),
52
52
  refetchInterval: 1e3
53
53
  });
54
+ const ref = React.useRef(null);
55
+ React.useEffect(() => {
56
+ if (!data?.ephemeralUrl) return;
57
+ const interval = setInterval(() => {
58
+ if (ref.current) {
59
+ ref.current.src = data.ephemeralUrl;
60
+ }
61
+ }, 45 * 1e3);
62
+ return () => clearInterval(interval);
63
+ }, [data?.ephemeralUrl]);
54
64
  if (isLoading) {
55
65
  return loadingComponent({
56
66
  devCommandRunning: false,
@@ -68,6 +78,7 @@ function FreestyleDevServerInner({
68
78
  return /* @__PURE__ */ React.createElement(
69
79
  "iframe",
70
80
  {
81
+ ref,
71
82
  sandbox: "allow-scripts allow-same-origin allow-forms",
72
83
  src: data.ephemeralUrl,
73
84
  style: {
@@ -49,6 +49,16 @@ function FreestyleDevServerInner({
49
49
  queryFn: async () => await requestDevServer({ repoUrl }),
50
50
  refetchInterval: 1e3
51
51
  });
52
+ const ref = React.useRef(null);
53
+ React.useEffect(() => {
54
+ if (!data?.ephemeralUrl) return;
55
+ const interval = setInterval(() => {
56
+ if (ref.current) {
57
+ ref.current.src = data.ephemeralUrl;
58
+ }
59
+ }, 45 * 1e3);
60
+ return () => clearInterval(interval);
61
+ }, [data?.ephemeralUrl]);
52
62
  if (isLoading) {
53
63
  return loadingComponent({
54
64
  devCommandRunning: false,
@@ -66,6 +76,7 @@ function FreestyleDevServerInner({
66
76
  return /* @__PURE__ */ React.createElement(
67
77
  "iframe",
68
78
  {
79
+ ref,
69
80
  sandbox: "allow-scripts allow-same-origin allow-forms",
70
81
  src: data.ephemeralUrl,
71
82
  style: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "freestyle-sandboxes",
3
- "version": "0.0.47",
3
+ "version": "0.0.49",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
package/src/index.ts CHANGED
@@ -811,6 +811,18 @@ export class FreestyleSandboxes {
811
811
  async requestDevServer({
812
812
  repoUrl
813
813
  }: { repoUrl: string }) {
814
+
815
+ function formatHook(serverUrl: string, repoUrl: string) {
816
+ const hook =
817
+ serverUrl +
818
+ "/__freestyle_dev_server/update/git?repo=" +
819
+ encodeURIComponent(repoUrl);
820
+
821
+ console.log(hook);
822
+ return hook;
823
+ }
824
+
825
+
814
826
  const response = await sandbox_openapi.handleEphemeralDevServer({
815
827
  client: this.client,
816
828
  body: {
@@ -818,6 +830,22 @@ export class FreestyleSandboxes {
818
830
  }
819
831
  });
820
832
 
833
+
834
+ if (response.data.isNew) {
835
+ const repoId = repoUrl.split("/").at(-1)!;
836
+
837
+ await this.createGitTrigger({
838
+ repoId: repoId,
839
+ action: {
840
+ endpoint: formatHook(response.data?.url!, repoUrl),
841
+ action: "webhook"
842
+ },
843
+ trigger: {
844
+ event: "push",
845
+ }
846
+ }).then(console.log);
847
+ }
848
+
821
849
  if (!response.data) {
822
850
  throw new Error(
823
851
  `Failed to request dev server: ${response.error}`,
@@ -81,6 +81,21 @@ function FreestyleDevServerInner({
81
81
  refetchInterval: 1000,
82
82
  });
83
83
 
84
+ // keep reloading the iframe because there's a bug where the websocket
85
+ // connection to the dev server is closed every 1 minute
86
+ const ref = React.useRef<HTMLIFrameElement>(null);
87
+ React.useEffect(() => {
88
+ if (!data?.ephemeralUrl) return;
89
+
90
+ const interval = setInterval(() => {
91
+ if (ref.current) {
92
+ ref.current.src = data.ephemeralUrl;
93
+ }
94
+ }, 45 * 1000);
95
+
96
+ return () => clearInterval(interval);
97
+ }, [data?.ephemeralUrl]);
98
+
84
99
  if (isLoading) {
85
100
  return loadingComponent({
86
101
  devCommandRunning: false,
@@ -99,6 +114,7 @@ function FreestyleDevServerInner({
99
114
 
100
115
  return (
101
116
  <iframe
117
+ ref={ref}
102
118
  sandbox="allow-scripts allow-same-origin allow-forms"
103
119
  src={data.ephemeralUrl}
104
120
  style={{