anbaric-web 1.51.0 → 1.52.0

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": "anbaric-web",
3
- "version": "1.51.0",
3
+ "version": "1.52.0",
4
4
  "description": "Shared platform web utilities: the app-proxy URL helpers and a safely-pooled Postgres client for plugin data functions",
5
5
  "license": "MIT",
6
6
  "author": "chris@anbaric.ai",
@@ -15,15 +15,26 @@ const KNOWN_PREFIXES = ["/api", "/app"];
15
15
  const isKnownPrefix = (pathname : string) : boolean =>
16
16
  KNOWN_PREFIXES.some(prefix => pathname === prefix || pathname.startsWith(`${prefix}/`));
17
17
 
18
- /* Places an absolute path onto the named app at /app/<appName>/<path>, or
19
- returns undefined (leave the path untouched) when there is no app, the path
20
- is not absolute (a relative or fully-qualified URL), or it is already under a
21
- known platform prefix (/api, /app - including an already-correct /app/... ). */
18
+ const isAbsoluteUrl = (value : string) : boolean => /^[a-z][a-z0-9+.-]*:/i.test(value) || value.startsWith("//");
19
+
20
+ /* Places a path onto the named app at /app/<appName>/<path>, or returns
21
+ undefined (leave it untouched) when there is no app, the value is a
22
+ fully-qualified URL, or it is already under a known platform prefix
23
+ (/api, /app - including an already-correct /app/... ).
24
+
25
+ A path without a leading slash is treated as app-relative rather than
26
+ refused. App authors are told to prefer relative links, precisely because
27
+ the app is mounted on a sub-path, so refusing them sent every such Await
28
+ link to the console root - the one shape the guidance asks for was the one
29
+ shape this would not rewrite. */
22
30
  const appInternalPath = (appName : string | undefined, pathname : string, search : string = "") : string | undefined => {
23
31
  if (!appName) return undefined;
24
- if (!pathname.startsWith("/")) return undefined;
25
- if (isKnownPrefix(pathname)) return undefined;
26
- return `/app/${appName}${pathname}${search}`;
32
+ if (isAbsoluteUrl(pathname)) return undefined;
33
+
34
+ const absolute = pathname.startsWith("/") ? pathname : `/${pathname}`;
35
+ if (isKnownPrefix(absolute)) return undefined;
36
+
37
+ return `/app/${appName}${absolute}${search}`;
27
38
  };
28
39
 
29
40
  /* The same rule for a whole URL string (path plus any query/hash), returning the