import pickBy from "lodash/pickBy.js";
import { safeJSONParse } from "../lib/tools.js";
import os from "os";
import url from "url";
import gitDescribe from "git-describe";
const __dirname = import.meta.dirname;
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const packageJson = require("../../package.json");
export function createOutputObject(args) {
    const uri_ins = args.url;
    const uri_ins_host = url.parse(uri_ins).hostname;
    const uri_refs = [uri_ins].concat(args.firstPartyUri);
    let output = {
        title: args.title || `Website Evidence Collection`,
        task_description: safeJSONParse(args.taskDescription),
        uri_ins: uri_ins,
        uri_refs: uri_refs,
        uri_dest: null,
        uri_redirects: null,
        secure_connection: {
            https_redirect: false,
            redirects: [],
            https_support: false,
            https_error: null,
            http_error: null,
        },
        testSSLError: null,
        testSSLErrorOutput: null,
        testSSLErrorCode: null,
        testSSL: null,
        host: uri_ins_host,
        script: {
            host: os.hostname(),
            version: {
                npm: packageJson.version,
                commit: null,
            },
            config: pickBy(args, (_value, key) => key === "_" || (key.length > 1 && !key.includes("-"))),
            cmd_args: process.argv.slice(2).join(" "),
            environment: pickBy(process.env, (_value, key) => {
                return (key.startsWith("WEC") ||
                    key.startsWith("PUPPETEER") ||
                    key.startsWith("CHROM"));
            }),
            node_version: process.version,
        },
        localStorage: null,
        cookies: [],
        beacons: [],
        links: {
            firstParty: [],
            thirdParty: [],
            social: [],
            keywords: [],
        },
        unsafeForms: [],
        browser: {
            name: "Chromium",
            version: "",
            user_agent: "",
            platform: {
                name: os.type(),
                version: os.release(),
            },
            extra_headers: { dnt: 0 },
            preset_cookies: {},
        },
        browsing_history: [],
        hosts: {},
        websockets: {},
        start_time: new Date(),
        end_time: null,
    };
    try {
        const gitInfo = gitDescribe.gitDescribeSync(__dirname);
        output.script.version.commit = gitInfo.raw;
    }
    catch (e) { }
    return output;
}
