24 lines
708 B
TypeScript
24 lines
708 B
TypeScript
import { Option, pipe } from "effect";
|
|
import { Page } from "playwright/test";
|
|
|
|
export type BackendHeaders = {
|
|
authString: string;
|
|
nonce: string;
|
|
};
|
|
|
|
/**
|
|
* @throws Lève une exception si la balise du JSON est introuvable.
|
|
*/
|
|
export const getBackendHeadersFromHtml = async (page: Page): Promise<BackendHeaders> => {
|
|
const backendHeaders: BackendHeaders | undefined = pipe(
|
|
Option.fromNullable(await page.locator("#injection-v2").textContent()),
|
|
Option.andThen(j => JSON.parse(j) as BackendHeaders),
|
|
Option.getOrUndefined,
|
|
);
|
|
|
|
if (backendHeaders === undefined) {
|
|
throw new Error("The JSON of the backend headers in the page's HTML can't be null.");
|
|
}
|
|
|
|
return backendHeaders;
|
|
};
|