@qontinui/ui-bridge-wrapper 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -1
- package/dist/capture-specs-cli.cjs +214 -108
- package/dist/capture-specs-cli.cjs.map +1 -1
- package/dist/capture-specs-cli.d.ts +3 -17
- package/dist/capture-specs-cli.d.ts.map +1 -1
- package/dist/cli-args.d.ts +65 -0
- package/dist/cli-args.d.ts.map +1 -0
- package/dist/index.cjs +14 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +14 -1
- package/dist/index.js.map +1 -1
- package/dist/inject-cli.cjs +35 -7
- package/dist/inject-cli.cjs.map +1 -1
- package/dist/inject-cli.d.ts.map +1 -1
- package/dist/login-drive.d.ts +71 -0
- package/dist/login-drive.d.ts.map +1 -0
- package/dist/login-web-cli.cjs +259 -127
- package/dist/login-web-cli.cjs.map +1 -1
- package/dist/login-web-cli.d.ts +15 -21
- package/dist/login-web-cli.d.ts.map +1 -1
- package/dist/transports/headless.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Cognito login drive + URL classifiers for the browser-driving package
|
|
3
|
+
* bins (`ui-bridge-login-web`, `ui-bridge-capture-specs`). Both CLIs used to
|
|
4
|
+
* carry their own (drifted) copies of this logic; this is the single home.
|
|
5
|
+
*
|
|
6
|
+
* The drive takes a Playwright {@link Page} directly (type-only import — the
|
|
7
|
+
* `playwright` package is a tsup EXTERNAL + a devDep, so nothing here couples to
|
|
8
|
+
* the transport / CLI layer or `InjectedContext`). It performs the OAuth chain
|
|
9
|
+
* from the app login page up to a *generic authed landing* and returns a
|
|
10
|
+
* structured {@link LoginDriveResult} — it never throws on a non-authed landing.
|
|
11
|
+
*/
|
|
12
|
+
import type { Page } from 'playwright';
|
|
13
|
+
/**
|
|
14
|
+
* Cognito is identified by HOST (custom domain / raw Cognito domain) or the
|
|
15
|
+
* /oauth2/ endpoints — never by a bare `/login?` path match: the app's own
|
|
16
|
+
* login URL legitimately carries a query now (`--url …/login?next=%2Fco-pilot`
|
|
17
|
+
* is the recommended deterministic-landing form since web #439), and a path
|
|
18
|
+
* match would (a) misreport a bounced-back-to-login failure as `stillOnCognito`
|
|
19
|
+
* instead of `onAppLoginPage`, and (b) let the step-2 waitForURL instant-match
|
|
20
|
+
* the app's own login page instead of waiting for the real hosted-UI hop (#85).
|
|
21
|
+
*/
|
|
22
|
+
export declare const isCognito: (u: string) => boolean;
|
|
23
|
+
/** Extract a URL's pathname; '' for an unparseable value. */
|
|
24
|
+
export declare const pathOf: (u: string) => string;
|
|
25
|
+
/**
|
|
26
|
+
* Strict success check: compare `success` against the URL's PATHNAME only.
|
|
27
|
+
* Matching the whole URL let query params fake success (e.g. `state=…/co-pilot`
|
|
28
|
+
* on a stuck /auth/callback) — see the 2026-06-04 false positive (#81).
|
|
29
|
+
*/
|
|
30
|
+
export declare const isSuccessPath: (u: string, success: string) => boolean;
|
|
31
|
+
/**
|
|
32
|
+
* True when the URL is the app's OWN /login page (not the Cognito hosted UI).
|
|
33
|
+
* Strict URL checks compare PATHNAMES, never the whole URL — a query param
|
|
34
|
+
* echoing a path (state=…%2Fco-pilot) must not fake a match (#81).
|
|
35
|
+
*/
|
|
36
|
+
export declare const isAppLoginPath: (u: string) => boolean;
|
|
37
|
+
/** Outcome of {@link loginDrive}. `ok` ⇒ landed on a generic authed page. */
|
|
38
|
+
export interface LoginDriveResult {
|
|
39
|
+
ok: boolean;
|
|
40
|
+
finalUrl: string;
|
|
41
|
+
landingPath: string;
|
|
42
|
+
errorText: string | null;
|
|
43
|
+
}
|
|
44
|
+
/** Options for {@link loginDrive}. */
|
|
45
|
+
export interface LoginDriveOptions {
|
|
46
|
+
email: string;
|
|
47
|
+
password: string;
|
|
48
|
+
/** Per-redirect-hop wait budget (ms). */
|
|
49
|
+
timeoutMs: number;
|
|
50
|
+
/** Optional stderr logger (each CLI passes its own prefixed logger). */
|
|
51
|
+
log?: (m: string) => void;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Scrape the first visible error card on the page into a <=500-char string, or
|
|
55
|
+
* null. Best-effort: a missing/empty card just yields null. Exported so callers
|
|
56
|
+
* that apply their own stricter post-drive assertions (login-web's `--success`)
|
|
57
|
+
* can reuse the same walk when THEIR check fails on a clean drive landing.
|
|
58
|
+
*/
|
|
59
|
+
export declare function scrapeErrorCard(page: Page): Promise<string | null>;
|
|
60
|
+
/**
|
|
61
|
+
* Drive the Cognito hosted-UI login flow from the app login page (already loaded
|
|
62
|
+
* in `page`) up to a generic authed landing (left Cognito AND not on
|
|
63
|
+
* `/auth/callback` AND not bounced back to the app login page).
|
|
64
|
+
*
|
|
65
|
+
* Returns a {@link LoginDriveResult}; it does NOT throw on a non-authed landing.
|
|
66
|
+
* Selector-walk failures inside the flow (e.g. "Cognito email field (visible)
|
|
67
|
+
* not found") still throw — those are real "the page isn't what we expected"
|
|
68
|
+
* conditions, not landing outcomes, and match both prior copies' behavior.
|
|
69
|
+
*/
|
|
70
|
+
export declare function loginDrive(page: Page, { email, password, timeoutMs, log }: LoginDriveOptions): Promise<LoginDriveResult>;
|
|
71
|
+
//# sourceMappingURL=login-drive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login-drive.d.ts","sourceRoot":"","sources":["../src/login-drive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,GAAI,GAAG,MAAM,KAAG,OACuB,CAAC;AAE9D,6DAA6D;AAC7D,eAAO,MAAM,MAAM,GAAI,GAAG,MAAM,KAAG,MAMlC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,GAAG,MAAM,EAAE,SAAS,MAAM,KAAG,OAC9B,CAAC;AAE9B;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,GAAG,MAAM,KAAG,OACU,CAAC;AAEtD,6EAA6E;AAC7E,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,OAAO,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,sCAAsC;AACtC,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,yCAAyC;IACzC,SAAS,EAAE,MAAM,CAAC;IAClB,wEAAwE;IACxE,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3B;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAiBxE;AAED;;;;;;;;;GASG;AACH,wBAAsB,UAAU,CAC9B,IAAI,EAAE,IAAI,EACV,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAc,EAAE,EAAE,iBAAiB,GAChE,OAAO,CAAC,gBAAgB,CAAC,CAiI3B"}
|
package/dist/login-web-cli.cjs
CHANGED
|
@@ -228,7 +228,20 @@ var HeadlessTransport = class extends BaseTransport {
|
|
|
228
228
|
};
|
|
229
229
|
}
|
|
230
230
|
async onReady() {
|
|
231
|
-
|
|
231
|
+
let launchHeadlessTab;
|
|
232
|
+
try {
|
|
233
|
+
({ launchHeadlessTab } = await import('@qontinui/ui-bridge-headless'));
|
|
234
|
+
} catch (err) {
|
|
235
|
+
const cause = err instanceof Error ? err.message : String(err);
|
|
236
|
+
throw new WrapperTransportError(
|
|
237
|
+
"INVALID_CONFIG",
|
|
238
|
+
`Transport kind '${this.kind}' needs the optional '@qontinui/ui-bridge-headless' peer, which is not installed. Install it and the Chromium browser:
|
|
239
|
+
npm i @qontinui/ui-bridge-headless && npx playwright install chromium
|
|
240
|
+
(bare \`npx @qontinui/ui-bridge-wrapper \u2026\` does NOT install peers \u2014 pass each peer with \`-p\`, e.g.
|
|
241
|
+
npx -y -p @qontinui/ui-bridge-wrapper -p @qontinui/ui-bridge -p @qontinui/ui-bridge-headless -p playwright ui-bridge-login-web \u2026)
|
|
242
|
+
Underlying import error: ${cause}`
|
|
243
|
+
);
|
|
244
|
+
}
|
|
232
245
|
const initScripts = await this.buildInitScripts();
|
|
233
246
|
const tab = await launchHeadlessTab({
|
|
234
247
|
url: this.options.targetUrl,
|
|
@@ -686,6 +699,183 @@ function createTransport(config) {
|
|
|
686
699
|
}
|
|
687
700
|
}
|
|
688
701
|
|
|
702
|
+
// src/cli-args.ts
|
|
703
|
+
var COMMON_FLAGS = /* @__PURE__ */ new Set(["--help", "-h", "--quiet"]);
|
|
704
|
+
function isFlagShaped(value) {
|
|
705
|
+
return value.startsWith("--");
|
|
706
|
+
}
|
|
707
|
+
var ArgReader = class {
|
|
708
|
+
argv;
|
|
709
|
+
error;
|
|
710
|
+
/**
|
|
711
|
+
* @param argv Already sliced past `node script`.
|
|
712
|
+
* @param known All flags the bin recognizes (union the bin's set with {@link COMMON_FLAGS}).
|
|
713
|
+
* @param error Factory producing the bin's domain error type.
|
|
714
|
+
*/
|
|
715
|
+
constructor(argv, known, error) {
|
|
716
|
+
this.argv = argv;
|
|
717
|
+
this.error = error;
|
|
718
|
+
for (const arg of argv) {
|
|
719
|
+
if (isFlagShaped(arg) && !known.has(arg)) {
|
|
720
|
+
throw error(`Unknown flag: ${arg}`);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
/** True if `name` appears as a bare boolean flag. */
|
|
725
|
+
has(name) {
|
|
726
|
+
return this.argv.includes(name);
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Value following the value-flag `name`, or `null` when the flag is absent OR
|
|
730
|
+
* has no following token (the caller defaults it). Throws when the following
|
|
731
|
+
* token is flag-shaped — the swallow this kit exists to kill.
|
|
732
|
+
*/
|
|
733
|
+
value(name) {
|
|
734
|
+
const i = this.argv.indexOf(name);
|
|
735
|
+
if (i < 0 || i + 1 >= this.argv.length) return null;
|
|
736
|
+
const raw = this.argv[i + 1];
|
|
737
|
+
if (isFlagShaped(raw)) {
|
|
738
|
+
throw this.error(
|
|
739
|
+
`${name} expects a value but got the flag '${raw}' \u2014 did you omit ${name}'s argument?`
|
|
740
|
+
);
|
|
741
|
+
}
|
|
742
|
+
return raw;
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
function makeLogger(prefix, quiet) {
|
|
746
|
+
if (quiet) return () => {
|
|
747
|
+
};
|
|
748
|
+
return (m) => process.stderr.write(`${prefix} ${m}
|
|
749
|
+
`) ;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
// src/login-drive.ts
|
|
753
|
+
var isCognito = (u) => /auth\.qontinui\.io|amazoncognito\.com|\/oauth2\//i.test(u);
|
|
754
|
+
var pathOf = (u) => {
|
|
755
|
+
try {
|
|
756
|
+
return new URL(u).pathname;
|
|
757
|
+
} catch {
|
|
758
|
+
return "";
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
var isSuccessPath = (u, success) => pathOf(u).includes(success);
|
|
762
|
+
var isAppLoginPath = (u) => /\/login(\b|\/|$)/.test(pathOf(u)) && !isCognito(u);
|
|
763
|
+
async function scrapeErrorCard(page) {
|
|
764
|
+
try {
|
|
765
|
+
const alerts = page.locator(
|
|
766
|
+
'[role="alert"], #loginErrorMessage, .error-message, [class*="error" i], [data-testid*="error" i]'
|
|
767
|
+
);
|
|
768
|
+
const an = await alerts.count();
|
|
769
|
+
for (let i = 0; i < an; i++) {
|
|
770
|
+
const el = alerts.nth(i);
|
|
771
|
+
if (await el.isVisible().catch(() => false)) {
|
|
772
|
+
const t = (await el.innerText().catch(() => "")).trim();
|
|
773
|
+
if (t) return t.slice(0, 500);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
} catch {
|
|
777
|
+
}
|
|
778
|
+
return null;
|
|
779
|
+
}
|
|
780
|
+
async function loginDrive(page, { email, password, timeoutMs, log = () => {
|
|
781
|
+
} }) {
|
|
782
|
+
log(`landed ${page.url()}`);
|
|
783
|
+
const emailBtn = page.getByRole("button", { name: /continue with email/i }).or(page.getByText(/continue with email/i));
|
|
784
|
+
await emailBtn.first().waitFor({ state: "visible", timeout: 15e3 });
|
|
785
|
+
await emailBtn.first().click();
|
|
786
|
+
await page.waitForURL(
|
|
787
|
+
(u) => {
|
|
788
|
+
const s = u.toString();
|
|
789
|
+
return isCognito(s) || !isAppLoginPath(s) && !/\/auth\/callback/.test(pathOf(s));
|
|
790
|
+
},
|
|
791
|
+
{ timeout: timeoutMs }
|
|
792
|
+
);
|
|
793
|
+
if (isCognito(page.url())) {
|
|
794
|
+
await page.waitForLoadState("domcontentloaded");
|
|
795
|
+
log(`cognito ${page.url()}`);
|
|
796
|
+
const fillFirst = async (sels, val, what) => {
|
|
797
|
+
for (const s of sels) {
|
|
798
|
+
const loc = page.locator(s);
|
|
799
|
+
const n = await loc.count().catch(() => 0);
|
|
800
|
+
for (let i = 0; i < n; i++) {
|
|
801
|
+
const el = loc.nth(i);
|
|
802
|
+
if (await el.isVisible().catch(() => false)) {
|
|
803
|
+
await el.fill(val, { timeout: 1e4 });
|
|
804
|
+
log(`filled ${what} via ${s} [visible #${i}]`);
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
throw new Error(`Cognito ${what} field (visible) not found (selectors: ${sels.join(", ")})`);
|
|
810
|
+
};
|
|
811
|
+
await fillFirst(
|
|
812
|
+
[
|
|
813
|
+
"#signInFormUsername",
|
|
814
|
+
'input[name="username"]',
|
|
815
|
+
'input[type="email"]',
|
|
816
|
+
'input[autocomplete="username"]'
|
|
817
|
+
],
|
|
818
|
+
email,
|
|
819
|
+
"email"
|
|
820
|
+
);
|
|
821
|
+
await fillFirst(
|
|
822
|
+
[
|
|
823
|
+
"#signInFormPassword",
|
|
824
|
+
'input[name="password"]',
|
|
825
|
+
'input[type="password"]',
|
|
826
|
+
'input[autocomplete="current-password"]'
|
|
827
|
+
],
|
|
828
|
+
password,
|
|
829
|
+
"password"
|
|
830
|
+
);
|
|
831
|
+
const submitLoc = page.locator(
|
|
832
|
+
'input[name="signInSubmitButton"], button[type="submit"], input[type="submit"], [name="signInSubmitButton"]'
|
|
833
|
+
);
|
|
834
|
+
let clicked = false;
|
|
835
|
+
const sn = await submitLoc.count().catch(() => 0);
|
|
836
|
+
for (let i = 0; i < sn; i++) {
|
|
837
|
+
const el = submitLoc.nth(i);
|
|
838
|
+
if (await el.isVisible().catch(() => false)) {
|
|
839
|
+
await el.click();
|
|
840
|
+
clicked = true;
|
|
841
|
+
log(`clicked submit [visible #${i}]`);
|
|
842
|
+
break;
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
if (!clicked) {
|
|
846
|
+
await page.getByRole("button", { name: /sign in|log in|continue|submit/i }).first().click();
|
|
847
|
+
log("clicked submit [role fallback]");
|
|
848
|
+
}
|
|
849
|
+
try {
|
|
850
|
+
await page.waitForURL(
|
|
851
|
+
(u) => {
|
|
852
|
+
const s = u.toString();
|
|
853
|
+
return !isCognito(s) && !/\/auth\/callback/.test(pathOf(s));
|
|
854
|
+
},
|
|
855
|
+
{ timeout: timeoutMs }
|
|
856
|
+
);
|
|
857
|
+
} catch {
|
|
858
|
+
const errorText2 = await scrapeErrorCard(page);
|
|
859
|
+
const finalUrl2 = page.url();
|
|
860
|
+
log(`final ${finalUrl2} (stalled)`);
|
|
861
|
+
return { ok: false, finalUrl: finalUrl2, landingPath: pathOf(finalUrl2), errorText: errorText2 };
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
await page.waitForLoadState("networkidle").catch(() => {
|
|
865
|
+
});
|
|
866
|
+
await page.waitForFunction(
|
|
867
|
+
() => window.__uiBridgeInjected?.ready === true,
|
|
868
|
+
{ timeout: 15e3 }
|
|
869
|
+
).catch(() => {
|
|
870
|
+
});
|
|
871
|
+
const finalUrl = page.url();
|
|
872
|
+
log(`final ${finalUrl}`);
|
|
873
|
+
const landingPath = await page.evaluate(() => location.pathname).catch(() => pathOf(finalUrl));
|
|
874
|
+
const ok = !isAppLoginPath(finalUrl) && !isCognito(finalUrl) && !/\/auth\/callback/.test(pathOf(finalUrl));
|
|
875
|
+
const errorText = ok ? null : await scrapeErrorCard(page);
|
|
876
|
+
return { ok, finalUrl, landingPath, errorText };
|
|
877
|
+
}
|
|
878
|
+
|
|
689
879
|
// src/login-web-cli.ts
|
|
690
880
|
var USAGE = `ui-bridge-login-web \u2014 automated web login via the UI Bridge injected transport
|
|
691
881
|
|
|
@@ -705,8 +895,19 @@ Options:
|
|
|
705
895
|
--post-login-click <css> Click this selector ONCE on the authed landing
|
|
706
896
|
(e.g. [data-testid='co-pilot-consent-allow']).
|
|
707
897
|
Non-fatal when the target never appears.
|
|
898
|
+
--expect-text <comma-list> Assert the authed page's body text contains EVERY
|
|
899
|
+
comma-separated entry. Missing entries fail the
|
|
900
|
+
exit code; the result JSON lists expectFound /
|
|
901
|
+
expectMissing. Matched case-sensitively.
|
|
902
|
+
--scroll-to <text> Before screenshotting, scroll the first element
|
|
903
|
+
containing this text into view (non-fatal if absent).
|
|
904
|
+
--screenshot <path> Write a full-page PNG of the authed landing to
|
|
905
|
+
<path> (captured BEFORE the --expect-text check, so
|
|
906
|
+
a failing assertion still leaves a diagnostic image).
|
|
708
907
|
--keep-open On success, park the authed session until SIGINT/
|
|
709
908
|
SIGTERM instead of closing the browser.
|
|
909
|
+
--quiet Suppress human-readable stderr logs (the JSON
|
|
910
|
+
result line still prints).
|
|
710
911
|
--help, -h Print this help and exit.
|
|
711
912
|
|
|
712
913
|
Prerequisites (packaged bin): the optional @qontinui/ui-bridge-headless peer must
|
|
@@ -719,6 +920,9 @@ Examples:
|
|
|
719
920
|
--success /build/workflows
|
|
720
921
|
ui-bridge-login-web --url "https://qontinui.io/login?next=%2Fco-pilot" \\
|
|
721
922
|
--success /co-pilot --post-login-click "[data-testid='co-pilot-consent-allow']" --keep-open
|
|
923
|
+
ui-bridge-login-web --url "https://qontinui.io/login?next=%2Foperations" \\
|
|
924
|
+
--success /operations --expect-text "option2-actions-outage-drill,metric_threshold" \\
|
|
925
|
+
--screenshot out.png
|
|
722
926
|
`;
|
|
723
927
|
var LoginCliArgError = class extends Error {
|
|
724
928
|
constructor(message) {
|
|
@@ -726,27 +930,11 @@ var LoginCliArgError = class extends Error {
|
|
|
726
930
|
this.name = "LoginCliArgError";
|
|
727
931
|
}
|
|
728
932
|
};
|
|
729
|
-
var isCognito = (u) => /auth\.qontinui\.io|amazoncognito\.com|\/oauth2\//i.test(u);
|
|
730
|
-
var pathOf = (u) => {
|
|
731
|
-
try {
|
|
732
|
-
return new URL(u).pathname;
|
|
733
|
-
} catch {
|
|
734
|
-
return "";
|
|
735
|
-
}
|
|
736
|
-
};
|
|
737
|
-
var isSuccessPath = (u, success) => pathOf(u).includes(success);
|
|
738
|
-
var isAppLoginPath = (u) => /\/login(\b|\/|$)/.test(pathOf(u)) && !isCognito(u);
|
|
739
933
|
function parseArgs(argv) {
|
|
740
|
-
const
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
const has = (name) => argv.includes(name);
|
|
745
|
-
for (const arg of argv) {
|
|
746
|
-
if (arg.startsWith("--") && !KNOWN_FLAGS.has(arg)) {
|
|
747
|
-
throw new LoginCliArgError(`Unknown flag: ${arg}`);
|
|
748
|
-
}
|
|
749
|
-
}
|
|
934
|
+
const mkError = (m) => new LoginCliArgError(m);
|
|
935
|
+
const reader = new ArgReader(argv, KNOWN_FLAGS, mkError);
|
|
936
|
+
const valueOf = (name) => reader.value(name);
|
|
937
|
+
const has = (name) => reader.has(name);
|
|
750
938
|
const help = has("--help") || has("-h");
|
|
751
939
|
const timeoutRaw = valueOf("--timeout");
|
|
752
940
|
const timeoutMs = timeoutRaw === null ? 6e4 : Number.parseInt(timeoutRaw, 10);
|
|
@@ -761,7 +949,11 @@ function parseArgs(argv) {
|
|
|
761
949
|
timeoutMs,
|
|
762
950
|
headed: has("--headed"),
|
|
763
951
|
postClick: valueOf("--post-login-click"),
|
|
952
|
+
expectText: (valueOf("--expect-text") ?? "").split(",").map((s) => s.trim()).filter((s) => s.length > 0),
|
|
953
|
+
scrollToText: valueOf("--scroll-to"),
|
|
954
|
+
screenshotPath: valueOf("--screenshot"),
|
|
764
955
|
keepOpen: has("--keep-open"),
|
|
956
|
+
quiet: has("--quiet"),
|
|
765
957
|
help
|
|
766
958
|
};
|
|
767
959
|
validateArgs(args);
|
|
@@ -775,9 +967,11 @@ var KNOWN_FLAGS = /* @__PURE__ */ new Set([
|
|
|
775
967
|
"--timeout",
|
|
776
968
|
"--headed",
|
|
777
969
|
"--post-login-click",
|
|
970
|
+
"--expect-text",
|
|
971
|
+
"--scroll-to",
|
|
972
|
+
"--screenshot",
|
|
778
973
|
"--keep-open",
|
|
779
|
-
|
|
780
|
-
"-h"
|
|
974
|
+
...COMMON_FLAGS
|
|
781
975
|
]);
|
|
782
976
|
function validateArgs(args) {
|
|
783
977
|
if (args.help) return;
|
|
@@ -790,10 +984,6 @@ function validateArgs(args) {
|
|
|
790
984
|
);
|
|
791
985
|
}
|
|
792
986
|
}
|
|
793
|
-
function log(m) {
|
|
794
|
-
process.stderr.write(`[login-web] ${m}
|
|
795
|
-
`);
|
|
796
|
-
}
|
|
797
987
|
async function main() {
|
|
798
988
|
let args;
|
|
799
989
|
try {
|
|
@@ -811,87 +1001,19 @@ ${USAGE}`);
|
|
|
811
1001
|
process.stdout.write(USAGE);
|
|
812
1002
|
process.exit(0);
|
|
813
1003
|
}
|
|
814
|
-
const { url, email, password, success, timeoutMs, headed, postClick } = args;
|
|
1004
|
+
const { url, email, password, success, timeoutMs, headed, postClick, expectText, scrollToText, screenshotPath } = args;
|
|
1005
|
+
const log = makeLogger("[login-web]", args.quiet);
|
|
815
1006
|
const transport = createTransport({
|
|
816
1007
|
kind: "injected",
|
|
817
1008
|
options: { targetUrl: url, waitForSettle: false, readyTimeoutMs: 45e3, headed }
|
|
818
1009
|
});
|
|
819
1010
|
transport.register("drive", async (_p, ctx) => {
|
|
820
1011
|
const page = ctx.page;
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
await page.waitForURL((u) => isCognito(u.toString()) || isSuccessPath(u.toString(), success), {
|
|
826
|
-
timeout: timeoutMs
|
|
827
|
-
});
|
|
828
|
-
if (isCognito(page.url())) {
|
|
829
|
-
await page.waitForLoadState("domcontentloaded");
|
|
830
|
-
log(`cognito ${page.url()}`);
|
|
831
|
-
const fillFirst = async (sels, val, what) => {
|
|
832
|
-
for (const s of sels) {
|
|
833
|
-
const loc = page.locator(s);
|
|
834
|
-
const n = await loc.count().catch(() => 0);
|
|
835
|
-
for (let i = 0; i < n; i++) {
|
|
836
|
-
const el = loc.nth(i);
|
|
837
|
-
if (await el.isVisible().catch(() => false)) {
|
|
838
|
-
await el.fill(val, { timeout: 1e4 });
|
|
839
|
-
log(`filled ${what} via ${s} [visible #${i}]`);
|
|
840
|
-
return;
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
throw new Error(`Cognito ${what} field (visible) not found (selectors: ${sels.join(", ")})`);
|
|
845
|
-
};
|
|
846
|
-
await fillFirst(
|
|
847
|
-
[
|
|
848
|
-
"#signInFormUsername",
|
|
849
|
-
'input[name="username"]',
|
|
850
|
-
'input[type="email"]',
|
|
851
|
-
'input[autocomplete="username"]'
|
|
852
|
-
],
|
|
853
|
-
email,
|
|
854
|
-
"email"
|
|
855
|
-
);
|
|
856
|
-
await fillFirst(
|
|
857
|
-
[
|
|
858
|
-
"#signInFormPassword",
|
|
859
|
-
'input[name="password"]',
|
|
860
|
-
'input[type="password"]',
|
|
861
|
-
'input[autocomplete="current-password"]'
|
|
862
|
-
],
|
|
863
|
-
password,
|
|
864
|
-
"password"
|
|
865
|
-
);
|
|
866
|
-
const submitLoc = page.locator(
|
|
867
|
-
'input[name="signInSubmitButton"], button[type="submit"], input[type="submit"], [name="signInSubmitButton"]'
|
|
868
|
-
);
|
|
869
|
-
let clicked = false;
|
|
870
|
-
const sn = await submitLoc.count().catch(() => 0);
|
|
871
|
-
for (let i = 0; i < sn; i++) {
|
|
872
|
-
const el = submitLoc.nth(i);
|
|
873
|
-
if (await el.isVisible().catch(() => false)) {
|
|
874
|
-
await el.click();
|
|
875
|
-
clicked = true;
|
|
876
|
-
log(`clicked submit [visible #${i}]`);
|
|
877
|
-
break;
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
if (!clicked) {
|
|
881
|
-
await page.getByRole("button", { name: /sign in|log in|continue|submit/i }).first().click();
|
|
882
|
-
log("clicked submit [role fallback]");
|
|
883
|
-
}
|
|
884
|
-
await page.waitForURL(
|
|
885
|
-
(u) => isSuccessPath(u.toString(), success) || /\/auth\/callback/.test(u.toString()),
|
|
886
|
-
{ timeout: timeoutMs }
|
|
887
|
-
);
|
|
888
|
-
if (/\/auth\/callback/.test(page.url())) {
|
|
889
|
-
await page.waitForURL((u) => isSuccessPath(u.toString(), success), { timeout: timeoutMs }).catch(() => {
|
|
890
|
-
});
|
|
891
|
-
}
|
|
1012
|
+
const r = await loginDrive(page, { email, password, timeoutMs, log });
|
|
1013
|
+
if (r.ok && !isSuccessPath(page.url(), success)) {
|
|
1014
|
+
await page.waitForURL((u) => isSuccessPath(u.toString(), success), { timeout: 1e4 }).catch(() => {
|
|
1015
|
+
});
|
|
892
1016
|
}
|
|
893
|
-
await page.waitForLoadState("networkidle").catch(() => {
|
|
894
|
-
});
|
|
895
1017
|
const finalUrl = page.url();
|
|
896
1018
|
log(`final ${finalUrl}`);
|
|
897
1019
|
await page.waitForFunction(() => window.__uiBridgeInjected?.ready === true, {
|
|
@@ -904,24 +1026,13 @@ ${USAGE}`);
|
|
|
904
1026
|
} catch {
|
|
905
1027
|
}
|
|
906
1028
|
const uiBridgeRoute = snap?.route ?? null;
|
|
907
|
-
const landingPath = uiBridgeRoute ?? pathOf(finalUrl);
|
|
908
|
-
const
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
);
|
|
915
|
-
const an = await alerts.count();
|
|
916
|
-
for (let i = 0; i < an && !errorText; i++) {
|
|
917
|
-
const el = alerts.nth(i);
|
|
918
|
-
if (await el.isVisible().catch(() => false)) {
|
|
919
|
-
const t = (await el.innerText().catch(() => "")).trim();
|
|
920
|
-
if (t) errorText = t.slice(0, 500);
|
|
921
|
-
}
|
|
922
|
-
}
|
|
923
|
-
} catch {
|
|
924
|
-
}
|
|
1029
|
+
const landingPath = uiBridgeRoute ?? (finalUrl === r.finalUrl ? r.landingPath : pathOf(finalUrl));
|
|
1030
|
+
const onAppLoginPage = isAppLoginPath(finalUrl);
|
|
1031
|
+
const stillOnCognito = isCognito(finalUrl);
|
|
1032
|
+
const ok = !onAppLoginPage && !stillOnCognito && landingPath.includes(success);
|
|
1033
|
+
let errorText = r.errorText;
|
|
1034
|
+
if (!ok && !errorText) {
|
|
1035
|
+
errorText = await scrapeErrorCard(page);
|
|
925
1036
|
}
|
|
926
1037
|
let postLoginClicked = null;
|
|
927
1038
|
if (ok && postClick) {
|
|
@@ -936,16 +1047,41 @@ ${USAGE}`);
|
|
|
936
1047
|
log(`post-login click target never visible (non-fatal): ${postClick}`);
|
|
937
1048
|
}
|
|
938
1049
|
}
|
|
1050
|
+
let screenshotWritten = null;
|
|
1051
|
+
if (ok && screenshotPath) {
|
|
1052
|
+
try {
|
|
1053
|
+
if (scrollToText) {
|
|
1054
|
+
await page.getByText(scrollToText).first().scrollIntoViewIfNeeded({ timeout: 5e3 }).catch(() => log(`scroll-to target not found (non-fatal): ${scrollToText}`));
|
|
1055
|
+
}
|
|
1056
|
+
await page.screenshot({ path: screenshotPath, fullPage: true });
|
|
1057
|
+
screenshotWritten = screenshotPath;
|
|
1058
|
+
log(`screenshot written: ${screenshotPath}`);
|
|
1059
|
+
} catch (err) {
|
|
1060
|
+
log(`screenshot failed (non-fatal): ${err instanceof Error ? err.message : String(err)}`);
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
let expectFound;
|
|
1064
|
+
let expectMissing;
|
|
1065
|
+
if (ok && expectText.length > 0) {
|
|
1066
|
+
const body = await page.evaluate(() => document.body?.innerText ?? "").catch(() => "");
|
|
1067
|
+
expectFound = expectText.filter((t) => body.includes(t));
|
|
1068
|
+
expectMissing = expectText.filter((t) => !body.includes(t));
|
|
1069
|
+
if (expectMissing.length > 0) log(`expect-text missing: ${expectMissing.join(", ")}`);
|
|
1070
|
+
}
|
|
1071
|
+
const finalOk = ok && (expectMissing?.length ?? 0) === 0;
|
|
939
1072
|
return {
|
|
940
|
-
ok,
|
|
1073
|
+
ok: finalOk,
|
|
941
1074
|
finalUrl,
|
|
942
1075
|
landingPath,
|
|
943
|
-
onAppLoginPage
|
|
944
|
-
stillOnCognito
|
|
1076
|
+
onAppLoginPage,
|
|
1077
|
+
stillOnCognito,
|
|
945
1078
|
errorText,
|
|
946
1079
|
uiBridgeRoute,
|
|
947
1080
|
uiBridgeRegistered: snap?.registration?.totalRegistered ?? null,
|
|
948
|
-
postLoginClicked
|
|
1081
|
+
postLoginClicked,
|
|
1082
|
+
expectFound,
|
|
1083
|
+
expectMissing,
|
|
1084
|
+
screenshotPath: screenshotPath ? screenshotWritten : void 0
|
|
949
1085
|
};
|
|
950
1086
|
});
|
|
951
1087
|
let result;
|
|
@@ -994,11 +1130,7 @@ if (isMain) {
|
|
|
994
1130
|
|
|
995
1131
|
exports.LoginCliArgError = LoginCliArgError;
|
|
996
1132
|
exports.USAGE = USAGE;
|
|
997
|
-
exports.isAppLoginPath = isAppLoginPath;
|
|
998
|
-
exports.isCognito = isCognito;
|
|
999
|
-
exports.isSuccessPath = isSuccessPath;
|
|
1000
1133
|
exports.parseArgs = parseArgs;
|
|
1001
|
-
exports.pathOf = pathOf;
|
|
1002
1134
|
exports.validateArgs = validateArgs;
|
|
1003
1135
|
//# sourceMappingURL=login-web-cli.cjs.map
|
|
1004
1136
|
//# sourceMappingURL=login-web-cli.cjs.map
|