2020-09-30 16:42:33 -04:00
|
|
|
import crypto from "crypto";
|
|
|
|
import { Frame } from "puppeteer";
|
|
|
|
|
|
|
|
export async function login(connectionString: string): Promise<Frame> {
|
2020-11-03 14:05:54 -05:00
|
|
|
const prodUrl = process.env.DATA_EXPLORER_ENDPOINT;
|
2020-11-13 10:58:38 -06:00
|
|
|
await page.goto(prodUrl);
|
2020-09-30 16:42:33 -04:00
|
|
|
|
2020-11-13 10:58:38 -06:00
|
|
|
if (process.env.PLATFORM === "Emulator") {
|
|
|
|
return page.mainFrame();
|
|
|
|
}
|
2020-09-30 16:42:33 -04:00
|
|
|
// log in with connection string
|
2021-01-19 16:31:55 -06:00
|
|
|
await page.waitFor("div > p.switchConnectTypeText", { visible: true });
|
|
|
|
await page.click("div > p.switchConnectTypeText");
|
|
|
|
const connStr = connectionString;
|
|
|
|
await page.type("input[class='inputToken']", connStr);
|
|
|
|
await page.click("input[value='Connect']");
|
2020-09-30 16:42:33 -04:00
|
|
|
const handle = await page.waitForSelector("iframe");
|
|
|
|
const frame = await handle.contentFrame();
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2020-11-02 14:33:14 -05:00
|
|
|
export function generateUniqueName(baseName = "", length = 4): string {
|
2020-09-30 16:42:33 -04:00
|
|
|
return `${baseName}${crypto.randomBytes(length).toString("hex")}`;
|
|
|
|
}
|