import * as DOH from "../components/reference/dns-over-https.js";
export const PRODUCTION = {
    apiPath: "/v2/api",
    lobby: "https://auth.fission.codes",
    server: "https://runfission.com",
    userDomain: "fission.name"
};
export const STAGING = {
    apiPath: "/v2/api",
    lobby: "https://auth.runfission.net",
    server: "https://runfission.net",
    userDomain: "fissionuser.net"
};
export function apiUrl(endpoints, suffix) {
    return `${endpoints.server}${endpoints.apiPath}${suffix?.length ? "/" + suffix.replace(/^\/+/, "") : ""}`;
}
// API
const didCache = {
    did: null,
    host: null,
    lastFetched: 0,
};
/**
 * Lookup the DID of a Fission API.
 * This function caches the DID for 3 hours.
 */
export async function did(endpoints) {
    let host;
    try {
        host = new URL(endpoints.server).host;
    }
    catch (e) {
        throw new Error("Unable to parse API Endpoint");
    }
    const now = Date.now(); // in milliseconds
    if (didCache.host !== host ||
        didCache.lastFetched + 1000 * 60 * 60 * 3 <= now) {
        didCache.did = await DOH.lookupTxtRecord("_did." + host);
        didCache.host = host;
        didCache.lastFetched = now;
    }
    if (!didCache.did)
        throw new Error("Couldn't get the Fission API DID");
    return didCache.did;
}
//# sourceMappingURL=fission.js.map