@ansiversa/components 0.0.147 → 0.0.148

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/README.md CHANGED
@@ -24,3 +24,10 @@ Inside any Ansiversa app (`web`, `admin`, or mini-apps):
24
24
 
25
25
  ```bash
26
26
  npm install @ansiversa/components
27
+ ```
28
+
29
+ ## Environment
30
+
31
+ - `PUBLIC_ANSIVERSA_PARENT_ORIGIN`: parent web origin used for shared footer legal/help links.
32
+ - Production example: `PUBLIC_ANSIVERSA_PARENT_ORIGIN=https://ansiversa.com`
33
+ - Local example: `PUBLIC_ANSIVERSA_PARENT_ORIGIN=http://localhost:2000`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ansiversa/components",
3
- "version": "0.0.147",
3
+ "version": "0.0.148",
4
4
  "description": "Shared UI components and layouts for the Ansiversa ecosystem",
5
5
  "type": "module",
6
6
  "exports": {
@@ -4,6 +4,7 @@ import AvFooter from "../AvFooter.astro";
4
4
  import AvMiniAppBar from "./AvMiniAppBar.astro";
5
5
  import AvNavbar from "../AvNavbar.astro";
6
6
  import AvNavbarActions from "../AvNavbarActions.astro";
7
+ import { buildParentUrl } from "../lib/urls/parentOrigin";
7
8
 
8
9
  interface Props {
9
10
  title?: string;
@@ -99,10 +100,10 @@ const ROOT_URL = rawDomain.match(/^https?:\/\//i)
99
100
  <!-- Footer -->
100
101
  <AvFooter
101
102
  links={[
102
- { label: "Terms", href: "/terms" },
103
- { label: "Privacy", href: "/privacy" },
104
- { label: "FAQ", href: "/faq" },
105
- { label: "Contact", href: "/contact" }
103
+ { label: "Terms", href: buildParentUrl("/terms") },
104
+ { label: "Privacy", href: buildParentUrl("/privacy") },
105
+ { label: "FAQ", href: buildParentUrl("/faq") },
106
+ { label: "Contact", href: buildParentUrl("/contact") }
106
107
  ]}
107
108
  />
108
109
  </body>
@@ -0,0 +1,36 @@
1
+ const DEFAULT_PARENT_ORIGIN = "http://localhost:2000";
2
+ const PRODUCTION_PARENT_ORIGIN = "https://ansiversa.com";
3
+
4
+ const trimTrailingSlash = (value: string) => value.trim().replace(/\/+$/, "");
5
+
6
+ const normalizeOrigin = (value: string) => {
7
+ const normalized = trimTrailingSlash(value);
8
+ if (!normalized) return "";
9
+ try {
10
+ return new URL(normalized).toString().replace(/\/+$/, "");
11
+ } catch {
12
+ return normalized;
13
+ }
14
+ };
15
+
16
+ const isAnsiversaHostname = (hostname: string) =>
17
+ hostname === "ansiversa.com" || hostname.endsWith(".ansiversa.com");
18
+
19
+ export const resolveParentOrigin = () => {
20
+ const envOrigin = normalizeOrigin(import.meta.env.PUBLIC_ANSIVERSA_PARENT_ORIGIN ?? "");
21
+ if (envOrigin) return envOrigin;
22
+
23
+ if (typeof window !== "undefined") {
24
+ const host = window.location.hostname.toLowerCase();
25
+ if (isAnsiversaHostname(host)) {
26
+ return PRODUCTION_PARENT_ORIGIN;
27
+ }
28
+ }
29
+
30
+ return DEFAULT_PARENT_ORIGIN;
31
+ };
32
+
33
+ export const buildParentUrl = (path: string) => {
34
+ const normalizedPath = `/${String(path ?? "").replace(/^\/+/, "")}`;
35
+ return `${resolveParentOrigin()}${normalizedPath}`;
36
+ };