@panomc/sdk 1.0.0-dev.57 → 1.0.0-dev.59

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.
@@ -9,6 +9,12 @@ import { show } from "$lib/components/ToastContainer.svelte";
9
9
  export const NETWORK_ERROR = 'NETWORK_ERROR';
10
10
  export const networkErrorBody = { result: 'error', error: NETWORK_ERROR };
11
11
 
12
+ const NETWORK_RETRY_DELAY_MS = 400;
13
+
14
+ function isIdempotent(method) {
15
+ return !method || ['GET', 'HEAD', 'OPTIONS'].includes(method.toUpperCase());
16
+ }
17
+
12
18
  // Function to build query parameters from an object
13
19
  export function buildQueryParams(params) {
14
20
  const queryString = Object.keys(params)
@@ -222,9 +228,25 @@ const ApiUtil = {
222
228
  }
223
229
 
224
230
  // Perform fetch request
225
- const fetchMethod =
231
+ const doFetch = () =>
226
232
  request && request.fetch ? request.fetch(path, options) : fetch(path, options);
227
233
 
234
+ // A request that never got a response (fetch rejected) is retried ONCE before the
235
+ // offline splash: browsers reuse a pooled HTTP/3 connection that the peer may have
236
+ // just idled out (Firefox: 30 s), and the request on it fails instantly although the
237
+ // server is fine. A new connection succeeds. Only idempotent methods, so a POST/PUT
238
+ // is never sent twice; HTTP error responses are not retried (fetch resolves them).
239
+ const fetchMethod =
240
+ browser && isIdempotent(data.method)
241
+ ? doFetch().catch((err) => {
242
+ if (err?.name === 'AbortError') throw err;
243
+
244
+ return new Promise((resolve) => setTimeout(resolve, NETWORK_RETRY_DELAY_MS)).then(
245
+ doFetch,
246
+ );
247
+ })
248
+ : doFetch();
249
+
228
250
  // Handle response
229
251
  return fetchMethod
230
252
  .then(bodyHandler)
@@ -30,11 +30,13 @@ export function checkDomainRedirection() {
30
30
  const apiUrl = new URL(API_URL);
31
31
  const currentUrl = new URL(window.location.href);
32
32
 
33
- if (
34
- currentUrl.hostname !== apiUrl.hostname ||
35
- currentUrl.port !== apiUrl.port ||
36
- currentUrl.protocol !== apiUrl.protocol
37
- ) {
33
+ // Only bounce when the page was opened on the vite port of the SAME machine
34
+ // (localhost:3000 -> localhost:8088). Reaching the Pano dev server through another
35
+ // hostname — a LAN address, ngrok, cloudflared — is legitimate: Pano already proxies vite
36
+ // for that visitor, and API_URL's host means nothing on their machine.
37
+ if (!isSameDevHost(currentUrl.hostname, apiUrl.hostname)) return;
38
+
39
+ if (currentUrl.port !== apiUrl.port || currentUrl.protocol !== apiUrl.protocol) {
38
40
  const basePath = UI_URL || PANEL_URL || SETUP_URL || '/';
39
41
  let pathname = currentUrl.pathname;
40
42
 
@@ -50,6 +52,16 @@ export function checkDomainRedirection() {
50
52
  }
51
53
  }
52
54
 
55
+ function isLoopbackHost(hostname) {
56
+ const h = hostname.toLowerCase();
57
+ return h === 'localhost' || h.endsWith('.localhost') || h === '[::1]' || h.startsWith('127.');
58
+ }
59
+
60
+ function isSameDevHost(a, b) {
61
+ const norm = (h) => (isLoopbackHost(h) ? 'localhost' : h.toLowerCase());
62
+ return norm(a) === norm(b);
63
+ }
64
+
53
65
  export function updateApiUrl(apiUrl) {
54
66
  API_URL = apiUrl;
55
67
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panomc/sdk",
3
- "version": "1.0.0-dev.57",
3
+ "version": "1.0.0-dev.59",
4
4
  "author": "PanoMC",
5
5
  "repository": {
6
6
  "url": "https://github.com/PanoMC/sdk"