diff --git a/config-sub-converter/scripts/test-options.js b/config-sub-converter/scripts/test-options.js index 108f592..366a716 100644 --- a/config-sub-converter/scripts/test-options.js +++ b/config-sub-converter/scripts/test-options.js @@ -15,32 +15,96 @@ function safeStringify(obj) { ); } -function globalKeysSample(limit = 200) { +function pickEnvSample() { try { - const keys = Object.getOwnPropertyNames(globalThis).sort(); - return keys.slice(0, limit); + const env = (typeof process !== "undefined" && process && process.env) ? process.env : null; + if (!env) return null; + + // only show safe-ish keys, no full dump + const keys = Object.keys(env).sort(); + const filtered = keys.filter(k => + k.toLowerCase().includes("sub") || + k.toLowerCase().includes("store") || + k.toLowerCase().includes("script") || + k.toLowerCase().includes("url") || + k.toLowerCase().includes("option") || + k.toLowerCase().includes("param") + ); + + const sample = {}; + for (const k of filtered.slice(0, 50)) sample[k] = env[k]; + return { keysCount: keys.length, filteredKeys: filtered.slice(0, 100), sample }; + } catch (e) { + return { error: String(e) }; + } +} + +function getGlobalDollarKeys() { + try { + return Object.getOwnPropertyNames(globalThis).filter(k => k.startsWith("$")).sort(); } catch { return []; } } -const report = { - types: { - $content: typeof $content, - $files: typeof $files, - $options: typeof $options, - ProxyUtils: typeof ProxyUtils, - produceArtifact: typeof produceArtifact, - }, - values: { - $contentPreview: (typeof $content === "string" ? $content.slice(0, 300) : $content), - $contentLength: (typeof $content === "string" ? $content.length : null), - $files: $files ?? null, - $options: $options ?? null, - }, - globals: { - globalThisKeysSample: globalKeysSample(), - } +// Safe "typeof" probes: never throws even if variable doesn't exist +const probes = { + $content: typeof $content, + $files: typeof $files, + $options: typeof $options, + + $params: typeof $params, + $args: typeof $args, + $arguments: typeof $arguments, + $argument: typeof $argument, + $argv: typeof $argv, + + $ctx: typeof $ctx, + $context: typeof $context, + $request: typeof $request, + $req: typeof $req, + $url: typeof $url, + $scriptUrl: typeof $scriptUrl, + $script_url: typeof $script_url, + + ProxyUtils: typeof ProxyUtils, + produceArtifact: typeof produceArtifact, + + process: typeof process, }; -$content = safeStringify(report); +const values = {}; +function maybeSet(name, getter) { + try { + const v = getter(); + // Avoid huge outputs + if (typeof v === "string") values[name] = v.length > 800 ? v.slice(0, 800) + "…(truncated)" : v; + else values[name] = v; + } catch (e) { + values[name] = { error: String(e) }; + } +} + +maybeSet("$options", () => (typeof $options !== "undefined" ? $options : null)); +maybeSet("$params", () => (typeof $params !== "undefined" ? $params : null)); +maybeSet("$args", () => (typeof $args !== "undefined" ? $args : null)); +maybeSet("$arguments", () => (typeof $arguments !== "undefined" ? $arguments : null)); +maybeSet("$argument", () => (typeof $argument !== "undefined" ? $argument : null)); +maybeSet("$ctx", () => (typeof $ctx !== "undefined" ? $ctx : null)); +maybeSet("$request", () => (typeof $request !== "undefined" ? $request : null)); +maybeSet("$url", () => (typeof $url !== "undefined" ? $url : null)); +maybeSet("$scriptUrl", () => (typeof $scriptUrl !== "undefined" ? $scriptUrl : null)); +maybeSet("$script_url", () => (typeof $script_url !== "undefined" ? $script_url : null)); + +maybeSet("$contentPreview", () => (typeof $content === "string" ? $content.slice(0, 300) : $content)); +maybeSet("$contentLength", () => (typeof $content === "string" ? $content.length : null)); +maybeSet("$files", () => (typeof $files !== "undefined" ? $files : null)); + +const report = { + probes, + values, + globalDollarKeys: getGlobalDollarKeys(), + envSample: pickEnvSample(), +}; + +$content = safeStringify(report); \ No newline at end of file