• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

graphty-org / graphty-element / 20514590651

26 Dec 2025 02:37AM UTC coverage: 70.559% (-0.3%) from 70.836%
20514590651

push

github

apowers313
ci: fix npm ci

9591 of 13363 branches covered (71.77%)

Branch coverage included in aggregate %.

25136 of 35854 relevant lines covered (70.11%)

6233.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.41
/src/logging/URLParamParser.ts
1
import {LogLevel, parseLogLevel} from "./types.js";
8!
2

3
/**
4
 * URL parameter names for logging configuration.
5
 */
6
const LOGGING_PARAM = "graphty-element-logging";
8✔
7
const LOG_LEVEL_PARAM = "graphty-element-log-level";
8✔
8
const REMOTE_LOG_PARAM = "graphty-element-remote-log";
8✔
9

10
/**
11
 * Parsed logging parameters from the URL.
12
 */
13
export interface ParsedLoggingParams {
14
    /** Whether logging is enabled */
15
    enabled: boolean;
16
    /** Modules to enable: array of module names or "*" for all */
17
    modules: string[] | "*";
18
    /** Global log level (if specified via graphty-element-log-level param) */
19
    level?: LogLevel;
20
    /** Per-module log level overrides (from module:level format) */
21
    moduleOverrides?: Map<string, LogLevel>;
22
    /** URL of remote log server (if specified via graphty-element-remote-log param) */
23
    remoteLogUrl?: string;
24
}
25

26
/**
27
 * Parse logging configuration from URL parameters.
28
 *
29
 * Supported URL parameter formats:
30
 * - `?graphty-element-logging=true` - Enable all logging at default level
31
 * - `?graphty-element-logging=layout,xr` - Enable specific modules
32
 * - `?graphty-element-logging=layout:debug,xr:info` - Enable modules with levels
33
 * - `?graphty-element-log-level=debug` - Set global log level
34
 * - `?graphty-element-remote-log=https://localhost:9080` - Send logs to remote server
35
 * @returns Parsed logging parameters, or null if logging param is not present or disabled
36
 */
37
export function parseLoggingURLParams(): ParsedLoggingParams | null {
8✔
38
    // Check if we're in a browser environment
39
    if (typeof window === "undefined" || typeof URLSearchParams === "undefined") {
200!
40
        return null;
×
41
    }
×
42

43
    const params = new URLSearchParams(window.location.search);
200✔
44
    const loggingValue = params.get(LOGGING_PARAM);
200✔
45
    const levelValue = params.get(LOG_LEVEL_PARAM);
200✔
46
    const remoteLogValue = params.get(REMOTE_LOG_PARAM);
200✔
47

48
    // No logging param or explicitly disabled
49
    if (!loggingValue || loggingValue === "" || loggingValue === "false") {
200✔
50
        return null;
175✔
51
    }
175!
52

53
    // Parse the logging value
54
    const result: ParsedLoggingParams = {
25✔
55
        enabled: true,
25✔
56
        modules: "*",
25✔
57
    };
25✔
58

59
    // "true" means enable all modules
60
    if (loggingValue === "true") {
32✔
61
        result.modules = "*";
17✔
62
    } else {
32✔
63
        // Parse module list (potentially with level overrides)
64
        const moduleSpecs = loggingValue.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
8✔
65
        const modules: string[] = [];
8✔
66
        const moduleOverrides = new Map<string, LogLevel>();
8✔
67

68
        for (const spec of moduleSpecs) {
8✔
69
            // Check for module:level format
70
            const colonIndex = spec.indexOf(":");
16✔
71
            if (colonIndex > 0) {
16✔
72
                const moduleName = spec.substring(0, colonIndex).trim();
8✔
73
                const levelStr = spec.substring(colonIndex + 1).trim();
8✔
74
                const level = parseLogLevel(levelStr);
8✔
75

76
                modules.push(moduleName);
8✔
77
                if (level !== undefined) {
8✔
78
                    moduleOverrides.set(moduleName, level);
7✔
79
                }
7✔
80
            } else {
16✔
81
                modules.push(spec);
8✔
82
            }
8✔
83
        }
16✔
84

85
        result.modules = modules;
8✔
86
        if (moduleOverrides.size > 0) {
8✔
87
            result.moduleOverrides = moduleOverrides;
4✔
88
        }
4✔
89
    }
8✔
90

91
    // Parse global log level if specified
92
    if (levelValue) {
32✔
93
        const level = parseLogLevel(levelValue);
11✔
94
        if (level !== undefined) {
11✔
95
            result.level = level;
10✔
96
        }
10✔
97
    }
11✔
98

99
    // Parse remote log server URL if specified
100
    if (remoteLogValue) {
32!
101
        // Validate it looks like a URL
102
        if (isValidUrl(remoteLogValue)) {
×
103
            result.remoteLogUrl = remoteLogValue;
×
104
        }
×
105
    }
✔
106

107
    return result;
25✔
108
}
25✔
109

110
/**
111
 * Check if a string is a valid URL.
112
 * @param urlString - The string to validate
113
 * @returns true if the string is a valid URL
114
 */
115
function isValidUrl(urlString: string): boolean {
×
116
    try {
×
117
        const url = new URL(urlString);
×
118
        // Only allow http and https protocols
119
        return url.protocol === "http:" || url.protocol === "https:";
×
120
    } catch {
×
121
        return false;
×
122
    }
×
123
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc