@kapeta/local-cluster-service 0.71.2 → 0.71.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.71.3](https://github.com/kapetacom/local-cluster-service/compare/v0.71.2...v0.71.3) (2024-09-18)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Let client know the new reset url ([efabbaa](https://github.com/kapetacom/local-cluster-service/commit/efabbaa4ce9aaf38cc98d6b31383d09d03ad0e9d))
7
+ * Reset page can redirect ([7efbc06](https://github.com/kapetacom/local-cluster-service/commit/7efbc06710226c4edba277749e0a8909fc010219))
8
+
1
9
  ## [0.71.2](https://github.com/kapetacom/local-cluster-service/compare/v0.71.1...v0.71.2) (2024-09-18)
2
10
 
3
11
 
@@ -29,11 +29,33 @@ class UIServer {
29
29
  async start() {
30
30
  const app = (0, express_1.default)();
31
31
  app.get('/_reset', (req, res) => {
32
+ /**
33
+ * Reset page clears local storage and session storage. If a redirect path is provided,
34
+ * it will redirect to that path.
35
+ */
32
36
  res.send(`
33
- <script>
34
- window.localStorage.clear();
35
- window.sessionStorage.clear();
36
- </script>`);
37
+ <html><head>
38
+ <script>
39
+ window.localStorage.clear();
40
+ window.sessionStorage.clear();
41
+
42
+ function isValidURL(url) {
43
+ try {
44
+ const parsedURL = new URL(url, window.location.origin);
45
+ return ['http:', 'https:'].includes(parsedURL.protocol);
46
+ } catch (e) {
47
+ return false;
48
+ }
49
+ }
50
+
51
+ const params = new URLSearchParams(window.location.search);
52
+ const redirect_path = params.get('redirect_path');
53
+
54
+ if (redirect_path && isValidURL(redirect_path)) {
55
+ window.location.href = redirect_path;
56
+ }
57
+ </script>
58
+ </head><body></body></html>`);
37
59
  });
38
60
  // Make it possible to serve static assets
39
61
  app.use(express_1.default.static((0, path_1.join)((0, page_utils_1.getSystemBaseDir)(this.systemId), 'public'), { fallthrough: true }));
@@ -66,7 +66,7 @@ router.post('/ui/serve/:systemId', async (req, res) => {
66
66
  if (!svr.isRunning()) {
67
67
  await UI_SERVERS[systemId].start();
68
68
  }
69
- res.status(200).send({ status: 'running', url: svr.getUrl() });
69
+ res.status(200).send({ status: 'running', url: svr.getUrl(), resetUrl: svr.resolveUrlFromPath('/_reset') });
70
70
  });
71
71
  router.post('/ui/create-system/:handle/:systemId', async (req, res) => {
72
72
  const systemId = req.params.systemId;
@@ -29,11 +29,33 @@ class UIServer {
29
29
  async start() {
30
30
  const app = (0, express_1.default)();
31
31
  app.get('/_reset', (req, res) => {
32
+ /**
33
+ * Reset page clears local storage and session storage. If a redirect path is provided,
34
+ * it will redirect to that path.
35
+ */
32
36
  res.send(`
33
- <script>
34
- window.localStorage.clear();
35
- window.sessionStorage.clear();
36
- </script>`);
37
+ <html><head>
38
+ <script>
39
+ window.localStorage.clear();
40
+ window.sessionStorage.clear();
41
+
42
+ function isValidURL(url) {
43
+ try {
44
+ const parsedURL = new URL(url, window.location.origin);
45
+ return ['http:', 'https:'].includes(parsedURL.protocol);
46
+ } catch (e) {
47
+ return false;
48
+ }
49
+ }
50
+
51
+ const params = new URLSearchParams(window.location.search);
52
+ const redirect_path = params.get('redirect_path');
53
+
54
+ if (redirect_path && isValidURL(redirect_path)) {
55
+ window.location.href = redirect_path;
56
+ }
57
+ </script>
58
+ </head><body></body></html>`);
37
59
  });
38
60
  // Make it possible to serve static assets
39
61
  app.use(express_1.default.static((0, path_1.join)((0, page_utils_1.getSystemBaseDir)(this.systemId), 'public'), { fallthrough: true }));
@@ -66,7 +66,7 @@ router.post('/ui/serve/:systemId', async (req, res) => {
66
66
  if (!svr.isRunning()) {
67
67
  await UI_SERVERS[systemId].start();
68
68
  }
69
- res.status(200).send({ status: 'running', url: svr.getUrl() });
69
+ res.status(200).send({ status: 'running', url: svr.getUrl(), resetUrl: svr.resolveUrlFromPath('/_reset') });
70
70
  });
71
71
  router.post('/ui/create-system/:handle/:systemId', async (req, res) => {
72
72
  const systemId = req.params.systemId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kapeta/local-cluster-service",
3
- "version": "0.71.2",
3
+ "version": "0.71.3",
4
4
  "description": "Manages configuration, ports and service discovery for locally running Kapeta systems",
5
5
  "type": "commonjs",
6
6
  "exports": {
@@ -30,12 +30,34 @@ export class UIServer {
30
30
  public async start() {
31
31
  const app = express();
32
32
  app.get('/_reset', (req: Request, res: Response) => {
33
+ /**
34
+ * Reset page clears local storage and session storage. If a redirect path is provided,
35
+ * it will redirect to that path.
36
+ */
33
37
  res.send(
34
38
  `
35
- <script>
36
- window.localStorage.clear();
37
- window.sessionStorage.clear();
38
- </script>`
39
+ <html><head>
40
+ <script>
41
+ window.localStorage.clear();
42
+ window.sessionStorage.clear();
43
+
44
+ function isValidURL(url) {
45
+ try {
46
+ const parsedURL = new URL(url, window.location.origin);
47
+ return ['http:', 'https:'].includes(parsedURL.protocol);
48
+ } catch (e) {
49
+ return false;
50
+ }
51
+ }
52
+
53
+ const params = new URLSearchParams(window.location.search);
54
+ const redirect_path = params.get('redirect_path');
55
+
56
+ if (redirect_path && isValidURL(redirect_path)) {
57
+ window.location.href = redirect_path;
58
+ }
59
+ </script>
60
+ </head><body></body></html>`
39
61
  );
40
62
  });
41
63
 
@@ -97,7 +97,7 @@ router.post('/ui/serve/:systemId', async (req: KapetaBodyRequest, res: Response)
97
97
  await UI_SERVERS[systemId].start();
98
98
  }
99
99
 
100
- res.status(200).send({ status: 'running', url: svr.getUrl() });
100
+ res.status(200).send({ status: 'running', url: svr.getUrl(), resetUrl: svr.resolveUrlFromPath('/_reset') });
101
101
  });
102
102
 
103
103
  router.post('/ui/create-system/:handle/:systemId', async (req: KapetaBodyRequest, res: Response) => {