@gsa-tts/graymatter-ui 0.3.21 → 0.3.22

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": "@gsa-tts/graymatter-ui",
3
- "version": "0.3.21",
3
+ "version": "0.3.22",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -8,7 +8,8 @@ import MobileBottomNav from '../components/MobileBottomNav.svelte';
8
8
  import MobileSideMenu from '../components/MobileSideMenu.svelte';
9
9
  import Logo from '../components/Logo.svelte';
10
10
  import { siteName } from '../constants';
11
- import { getAppUrls } from '../utils/getAppUrls';
11
+ import { getUrlFromBase } from '../helpers/url.js';
12
+ import { getSecret } from 'astro:env/server';
12
13
 
13
14
  const {
14
15
  componentOptions = {},
@@ -24,7 +25,17 @@ const {
24
25
  hideDiscover = true,
25
26
  } = Astro.props;
26
27
 
27
- const { api, chat, console, discover } = getAppUrls();
28
+ // Use getSecret directly for better environment variable handling
29
+ const chatUrl = getSecret('CHAT_URL') || getSecret('PUBLIC_CHAT_URL');
30
+ const consoleUrl = getSecret('CONSOLE_URL') || getSecret('PUBLIC_CONSOLE_URL');
31
+ const apiUrl = getSecret('API_URL') || getSecret('PUBLIC_API_URL');
32
+ const discoverUrl =
33
+ getSecret('DISCOVER_URL') || getSecret('PUBLIC_DISCOVER_URL');
34
+
35
+ const chat = chatUrl || '#';
36
+ const console = consoleUrl || '#';
37
+ const api = apiUrl || getUrlFromBase('/api/documentation');
38
+ const discover = discoverUrl || '#';
28
39
  ---
29
40
 
30
41
  <BaseLayout title={pageTitle} {gtmID} {description} {openGraphImage}>
@@ -66,7 +66,7 @@ function processUrl(url: string | undefined, fallback: string): string {
66
66
  *
67
67
  * @param envArg - Optional environment object to use instead of `import.meta.env`.
68
68
  * Useful for testing or when you want to override environment variables.
69
- * If not provided, uses Vite's `import.meta.env`.
69
+ * If not provided, uses `process.env` (server) or `import.meta.env` (client).
70
70
  *
71
71
  * @returns An object containing processed URLs/paths for each application section:
72
72
  * - `chat`: Chat application URL or path
@@ -102,31 +102,51 @@ function processUrl(url: string | undefined, fallback: string): string {
102
102
  * ```
103
103
  *
104
104
  * @remarks
105
+ * - Uses `process.env` in server context, `import.meta.env` in client context
106
+ * - Supports both `CHAT_URL` and `PUBLIC_CHAT_URL` naming conventions
105
107
  * - URLs are processed through `processUrl()` which handles both absolute and relative URLs
106
- * - Relative URLs are processed through `getUrlFromBase()` to create full URLs
107
108
  * - Missing environment variables result in fallback values (`#` for most, `/api/documentation` for API)
108
109
  * - Warnings are logged in development when environment variables are missing
109
- * - The function is designed to work with Vite's `import.meta.env` system
110
+ * - The function is designed to work with both Vite's `import.meta.env` and Node.js `process.env`
111
+ * - Note: Astro layouts (like GlobalAppLayout.astro) use `getSecret()` directly for better performance
110
112
  *
111
113
  * @see {@link processUrl} - URL processing logic
112
114
  * @see {@link getUrlFromBase} - Base URL resolution
113
115
  */
114
116
  export function getAppUrls(envArg?: Record<string, string | undefined>) {
115
- const env = envArg || import.meta.env;
116
- const fallback = '#';
117
+ // If envArg is provided, use it directly (for testing)
118
+ if (envArg) {
119
+ const chatUrl = envArg.CHAT_URL || envArg.PUBLIC_CHAT_URL;
120
+ const consoleUrl = envArg.CONSOLE_URL || envArg.PUBLIC_CONSOLE_URL;
121
+ const apiUrl = envArg.API_URL || envArg.PUBLIC_API_URL;
122
+ const discoverUrl = envArg.DISCOVER_URL || envArg.PUBLIC_DISCOVER_URL;
117
123
 
118
- const chatUrl = env.PUBLIC_CHAT_URL;
119
- const consoleUrl = env.PUBLIC_CONSOLE_URL;
120
- const apiUrl = env.PUBLIC_API_URL;
121
- const discoverUrl = env.PUBLIC_DISCOVER_URL;
124
+ warnIfMissing('chat', chatUrl);
125
+ warnIfMissing('console', consoleUrl);
126
+ warnIfMissing('api', apiUrl);
127
+
128
+ return {
129
+ chat: processUrl(chatUrl, '#'),
130
+ console: processUrl(consoleUrl, '#'),
131
+ api: processUrl(apiUrl, getUrlFromBase('/api/documentation')),
132
+ discover: processUrl(discoverUrl, '#'),
133
+ };
134
+ }
135
+
136
+ // Use process.env in server context, import.meta.env in client context
137
+ const env = typeof window === 'undefined' ? process.env : import.meta.env;
138
+ const chatUrl = env.CHAT_URL || env.PUBLIC_CHAT_URL;
139
+ const consoleUrl = env.CONSOLE_URL || env.PUBLIC_CONSOLE_URL;
140
+ const apiUrl = env.API_URL || env.PUBLIC_API_URL;
141
+ const discoverUrl = env.DISCOVER_URL || env.PUBLIC_DISCOVER_URL;
122
142
 
123
143
  warnIfMissing('chat', chatUrl);
124
144
  warnIfMissing('console', consoleUrl);
125
145
  warnIfMissing('api', apiUrl);
126
146
 
127
147
  return {
128
- chat: processUrl(chatUrl, fallback),
129
- console: processUrl(consoleUrl, fallback),
148
+ chat: processUrl(chatUrl, '#'),
149
+ console: processUrl(consoleUrl, '#'),
130
150
  api: processUrl(apiUrl, getUrlFromBase('/api/documentation')),
131
151
  discover: processUrl(discoverUrl, '#'),
132
152
  };