@gsa-tts/graymatter-ui 0.4.1 → 0.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gsa-tts/graymatter-ui",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -62,8 +62,8 @@
62
62
  "vite": "^6.3.5",
63
63
  "vitest": "^3.0.7",
64
64
  "@gsa-tts/graymatter-eslint": "0.0.2",
65
- "@gsa-tts/graymatter-vitest-config": "0.0.1",
66
- "@gsa-tts/graymatter-typescript-config": "0.0.2"
65
+ "@gsa-tts/graymatter-typescript-config": "0.0.2",
66
+ "@gsa-tts/graymatter-vitest-config": "0.0.1"
67
67
  },
68
68
  "dependencies": {
69
69
  "@fontsource-variable/archivo": "^5.2.6",
@@ -2,7 +2,6 @@
2
2
  // These are Astro-specific utilities that should only be imported directly by their specific paths.
3
3
  // Exporting them would cause bundling issues for Svelte/SvelteKit apps that import from this barrel export.
4
4
 
5
- export * from './getAppUrls.js';
6
5
  export * from './navigationControl.js';
7
6
  export * from './copyButtonScript.js';
8
7
  export * from './generateApiNavData.js';
@@ -28,18 +28,15 @@ export function setupCommonMocks() {
28
28
  };
29
29
  });
30
30
 
31
- vi.mock('../utils/getAppUrls', () => ({
32
- getAppUrls: () => ({
33
- discover: '/fake-discover',
34
- chat: '/fake-chat',
35
- console: '/fake-console',
36
- api: '/fake-api',
37
- }),
38
- }));
39
-
40
- vi.mock('slugify', () => ({
41
- default: (x: string) => x.toLowerCase().replace(/ /g, '-'),
42
- }));
31
+ vi.mock('slugify', () => {
32
+ const mockSlugify = (x: string) => x.toLowerCase().replace(/ /g, '-');
33
+ return {
34
+ __esModule: true,
35
+ default: mockSlugify,
36
+ // Support both named and default exports
37
+ slugify: mockSlugify,
38
+ };
39
+ });
43
40
 
44
41
  vi.stubGlobal(
45
42
  'window',
@@ -1,35 +0,0 @@
1
- import { glob } from 'astro/loaders';
2
-
3
- /**
4
- * Creates the API documentation collection for Astro apps.
5
- *
6
- * @example
7
- * ```typescript
8
- * import { defineCollection, z } from 'astro:content';
9
- * import { createApiDocumentationCollection } from '@gsa-tts/graymatter-ui/utils/apiDocumentationConfig.js';
10
- *
11
- * export const collections = {
12
- * apiDocumentation: createApiDocumentationCollection({ defineCollection, z }),
13
- * };
14
- * ```
15
- */
16
- export function createApiDocumentationCollection({
17
- defineCollection,
18
- z,
19
- }: {
20
- defineCollection: typeof import('astro:content').defineCollection;
21
- z: typeof import('astro:content').z;
22
- }) {
23
- return defineCollection({
24
- loader: glob({
25
- base: './node_modules/@gsa-tts/graymatter-ui/src/content/api',
26
- pattern: '**/*.{md,mdx}',
27
- }),
28
- schema: () =>
29
- z.object({
30
- title: z.string(),
31
- description: z.string(),
32
- sortOrder: z.number(),
33
- }),
34
- });
35
- }
@@ -1,153 +0,0 @@
1
- import { getUrlFromBase } from '@gsa-tts/graymatter-ui/helpers/url.js';
2
-
3
- /**
4
- * Logs a warning message when an environment variable is missing.
5
- *
6
- * @param name - The name of the missing environment variable
7
- * @param value - The value of the environment variable (should be undefined)
8
- */
9
- function warnIfMissing(name: string, value: string | undefined) {
10
- if (!value) {
11
- console.warn(`[getAppUrls] Environment variable for ${name} is missing!`);
12
- }
13
- }
14
-
15
- /**
16
- * Checks if a URL is absolute (starts with protocol like http:// or https://).
17
- *
18
- * @param url - The URL string to check
19
- * @returns True if the URL is absolute, false otherwise
20
- */
21
- function isAbsoluteUrl(url: string): boolean {
22
- try {
23
- new URL(url);
24
- return true;
25
- } catch {
26
- return false;
27
- }
28
- }
29
-
30
- /**
31
- * Processes a URL string, handling both absolute and relative URLs.
32
- *
33
- * If the URL is undefined, returns the fallback. If it's absolute (starts with protocol),
34
- * returns it as-is. If it's relative, processes it through `getUrlFromBase()` to create
35
- * a full URL.
36
- *
37
- * @param url - The URL string to process (can be undefined)
38
- * @param fallback - The fallback URL to use if the input URL is undefined
39
- * @returns The processed URL string (can be absolute URL or relative path)
40
- *
41
- * @example
42
- * ```typescript
43
- * processUrl('https://example.com', '/fallback'); // "https://example.com"
44
- * processUrl('/api/docs', '/fallback'); // "/api/docs" (processed by getUrlFromBase)
45
- * processUrl(undefined, '/fallback'); // "/fallback"
46
- * ```
47
- */
48
- function processUrl(url: string | undefined, fallback: string): string {
49
- if (!url) {
50
- return fallback;
51
- }
52
-
53
- if (isAbsoluteUrl(url)) {
54
- return url;
55
- }
56
-
57
- return getUrlFromBase(url);
58
- }
59
-
60
- /**
61
- * Retrieves application URLs/paths from environment variables with fallback support.
62
- *
63
- * This utility function processes environment variables to provide URLs or paths for different
64
- * application sections (chat, console, API, discover). It supports both absolute URLs
65
- * and relative paths, with intelligent fallback handling.
66
- *
67
- * @param envArg - Optional environment object to use instead of `import.meta.env`.
68
- * Useful for testing or when you want to override environment variables.
69
- * If not provided, uses `process.env` (server) or `import.meta.env` (client).
70
- *
71
- * @returns An object containing processed URLs/paths for each application section:
72
- * - `chat`: Chat application URL or path
73
- * - `console`: Console application URL or path
74
- * - `api`: API documentation URL or path
75
- * - `discover`: Discover page URL or path
76
- *
77
- * @example
78
- * ```typescript
79
- * // Using default environment variables
80
- * const urls = getAppUrls();
81
- * console.log(urls.chat); // "#" (fallback) or "https://chat.example.com" (URL)
82
- *
83
- * // Using custom environment object (useful for testing)
84
- * const urls = getAppUrls({
85
- * PUBLIC_CHAT_URL: 'https://chat.dev/',
86
- * PUBLIC_CONSOLE_URL: 'https://console.dev/',
87
- * PUBLIC_API_URL: 'https://api.dev/docs',
88
- * PUBLIC_DISCOVER_URL: 'https://discover.dev/'
89
- * });
90
- * ```
91
- *
92
- * @example
93
- * ```typescript
94
- * // Environment variables (.env file)
95
- * PUBLIC_CHAT_URL=https://chat.example.com
96
- * PUBLIC_CONSOLE_URL=https://console.example.com
97
- * PUBLIC_API_URL=/api/documentation
98
- * PUBLIC_DISCOVER_URL=https://discover.example.com
99
- *
100
- * // Usage in code
101
- * const { chat, console, api, discover } = getAppUrls();
102
- * ```
103
- *
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
107
- * - URLs are processed through `processUrl()` which handles both absolute and relative URLs
108
- * - Missing environment variables result in fallback values (`#` for most, `/api/documentation` for API)
109
- * - Warnings are logged in development when environment variables are missing
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
112
- *
113
- * @see {@link processUrl} - URL processing logic
114
- * @see {@link getUrlFromBase} - Base URL resolution
115
- */
116
- export function getAppUrls(envArg?: Record<string, string | undefined>) {
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;
123
-
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;
142
-
143
- warnIfMissing('chat', chatUrl);
144
- warnIfMissing('console', consoleUrl);
145
- warnIfMissing('api', apiUrl);
146
-
147
- return {
148
- chat: processUrl(chatUrl, '#'),
149
- console: processUrl(consoleUrl, '#'),
150
- api: processUrl(apiUrl, getUrlFromBase('/api/documentation')),
151
- discover: processUrl(discoverUrl, '#'),
152
- };
153
- }