@qontinui/ui-bridge-wrapper 0.4.0 → 0.4.2
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 +55 -1
- package/dist/capture-specs-cli.cjs +249 -119
- 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 +75 -0
- package/dist/cli-args.d.ts.map +1 -0
- package/dist/index.cjs +46 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +46 -12
- package/dist/index.js.map +1 -1
- package/dist/inject-cli.cjs +80 -31
- 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 +306 -140
- 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/react/index.cjs +4 -4
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +4 -4
- package/dist/react/index.js.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,CAoI3B"}
|
package/dist/login-web-cli.cjs
CHANGED
|
@@ -228,19 +228,53 @@ 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
|
+
const code = err?.code;
|
|
237
|
+
if (code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND") {
|
|
238
|
+
throw new WrapperTransportError(
|
|
239
|
+
"INVALID_CONFIG",
|
|
240
|
+
`Transport kind '${this.kind}' needs the optional '@qontinui/ui-bridge-headless' peer, which is not installed. Install it and the Chromium browser:
|
|
241
|
+
npm i @qontinui/ui-bridge-headless && npx playwright install chromium
|
|
242
|
+
(bare \`npx @qontinui/ui-bridge-wrapper \u2026\` does NOT install peers \u2014 pass each peer with \`-p\`, e.g.
|
|
243
|
+
npx -y -p @qontinui/ui-bridge-wrapper -p @qontinui/ui-bridge -p @qontinui/ui-bridge-headless -p playwright ui-bridge-login-web \u2026)
|
|
244
|
+
Underlying import error: ${cause}`
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
throw new WrapperTransportError(
|
|
248
|
+
"INVALID_CONFIG",
|
|
249
|
+
`'@qontinui/ui-bridge-headless' is installed but failed to load \u2014 this is a broken install (missing transitive dependency or version skew), not a missing peer. Try reinstalling it. Underlying error: ${cause}`
|
|
250
|
+
);
|
|
251
|
+
}
|
|
232
252
|
const initScripts = await this.buildInitScripts();
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
253
|
+
let tab;
|
|
254
|
+
try {
|
|
255
|
+
tab = await launchHeadlessTab({
|
|
256
|
+
url: this.options.targetUrl,
|
|
257
|
+
headless: this.headless,
|
|
258
|
+
uiBridgeBase: this.options.uiBridgeBase,
|
|
259
|
+
waitForUiBridgeMs: this.options.waitForUiBridgeMs,
|
|
260
|
+
viewportWidth: this.options.viewportWidth,
|
|
261
|
+
viewportHeight: this.options.viewportHeight,
|
|
262
|
+
userAgent: this.options.userAgent,
|
|
263
|
+
forwardConsole: this.options.forwardConsole,
|
|
264
|
+
initScripts: initScripts.length > 0 ? initScripts : void 0
|
|
265
|
+
});
|
|
266
|
+
} catch (err) {
|
|
267
|
+
const cause = err instanceof Error ? err.message : String(err);
|
|
268
|
+
if (/Executable doesn't exist|browserType\.launch/i.test(cause)) {
|
|
269
|
+
throw new WrapperTransportError(
|
|
270
|
+
"INVALID_CONFIG",
|
|
271
|
+
`Playwright's Chromium browser is not installed (the '@qontinui/ui-bridge-headless' peer itself loaded fine). Run:
|
|
272
|
+
npx playwright install chromium
|
|
273
|
+
Underlying launch error: ${cause}`
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
throw err;
|
|
277
|
+
}
|
|
244
278
|
this.tab = {
|
|
245
279
|
browser: tab.browser,
|
|
246
280
|
context: tab.context,
|
|
@@ -686,6 +720,194 @@ function createTransport(config) {
|
|
|
686
720
|
}
|
|
687
721
|
}
|
|
688
722
|
|
|
723
|
+
// src/cli-args.ts
|
|
724
|
+
var COMMON_FLAGS = /* @__PURE__ */ new Set(["--help", "-h", "--quiet"]);
|
|
725
|
+
function isFlagShaped(value) {
|
|
726
|
+
return value.startsWith("--");
|
|
727
|
+
}
|
|
728
|
+
function consumeValue(flag, raw, error) {
|
|
729
|
+
if (raw === void 0) return null;
|
|
730
|
+
if (isFlagShaped(raw)) {
|
|
731
|
+
throw error(`${flag} expects a value but got the flag '${raw}' \u2014 did you omit ${flag}'s argument?`);
|
|
732
|
+
}
|
|
733
|
+
return raw;
|
|
734
|
+
}
|
|
735
|
+
function rejectEmptyValue(flag, value, error) {
|
|
736
|
+
if (value !== null && value.trim() === "") {
|
|
737
|
+
throw error(
|
|
738
|
+
`${flag} was given an empty value \u2014 omit the flag to use its default, or pass a non-empty value`
|
|
739
|
+
);
|
|
740
|
+
}
|
|
741
|
+
return value;
|
|
742
|
+
}
|
|
743
|
+
var ArgReader = class {
|
|
744
|
+
argv;
|
|
745
|
+
error;
|
|
746
|
+
/**
|
|
747
|
+
* @param argv Already sliced past `node script`.
|
|
748
|
+
* @param known All flags the bin recognizes (union the bin's set with {@link COMMON_FLAGS}).
|
|
749
|
+
* @param error Factory producing the bin's domain error type.
|
|
750
|
+
*/
|
|
751
|
+
constructor(argv, known, error) {
|
|
752
|
+
this.argv = argv;
|
|
753
|
+
this.error = error;
|
|
754
|
+
for (const arg of argv) {
|
|
755
|
+
if (isFlagShaped(arg) && !known.has(arg)) {
|
|
756
|
+
throw error(`Unknown flag: ${arg}`);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
/** True if `name` appears as a bare boolean flag. */
|
|
761
|
+
has(name) {
|
|
762
|
+
return this.argv.includes(name);
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Value following the value-flag `name`, or `null` when the flag is absent OR
|
|
766
|
+
* has no following token (the caller defaults it). Throws when the following
|
|
767
|
+
* token is flag-shaped — the swallow this kit exists to kill. Delegates to
|
|
768
|
+
* {@link consumeValue} so the guard (and its message) live in exactly one
|
|
769
|
+
* place for both the indexOf-style and switch-style parsers.
|
|
770
|
+
*/
|
|
771
|
+
value(name) {
|
|
772
|
+
const i = this.argv.indexOf(name);
|
|
773
|
+
if (i < 0 || i + 1 >= this.argv.length) return null;
|
|
774
|
+
return consumeValue(name, this.argv[i + 1], this.error);
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
function makeLogger(prefix, quiet) {
|
|
778
|
+
if (quiet) return () => {
|
|
779
|
+
};
|
|
780
|
+
return (m) => process.stderr.write(`${prefix} ${m}
|
|
781
|
+
`) ;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
// src/login-drive.ts
|
|
785
|
+
var isCognito = (u) => /auth\.qontinui\.io|amazoncognito\.com|\/oauth2\//i.test(u);
|
|
786
|
+
var pathOf = (u) => {
|
|
787
|
+
try {
|
|
788
|
+
return new URL(u).pathname;
|
|
789
|
+
} catch {
|
|
790
|
+
return "";
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
var isSuccessPath = (u, success) => pathOf(u).includes(success);
|
|
794
|
+
var isAppLoginPath = (u) => /\/login(\b|\/|$)/.test(pathOf(u)) && !isCognito(u);
|
|
795
|
+
async function scrapeErrorCard(page) {
|
|
796
|
+
try {
|
|
797
|
+
const alerts = page.locator(
|
|
798
|
+
'[role="alert"], #loginErrorMessage, .error-message, [class*="error" i], [data-testid*="error" i]'
|
|
799
|
+
);
|
|
800
|
+
const an = await alerts.count();
|
|
801
|
+
for (let i = 0; i < an; i++) {
|
|
802
|
+
const el = alerts.nth(i);
|
|
803
|
+
if (await el.isVisible().catch(() => false)) {
|
|
804
|
+
const t = (await el.innerText().catch(() => "")).trim();
|
|
805
|
+
if (t) return t.slice(0, 500);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
} catch {
|
|
809
|
+
}
|
|
810
|
+
return null;
|
|
811
|
+
}
|
|
812
|
+
async function loginDrive(page, { email, password, timeoutMs, log = () => {
|
|
813
|
+
} }) {
|
|
814
|
+
log(`landed ${page.url()}`);
|
|
815
|
+
const emailBtn = page.getByRole("button", { name: /continue with email/i }).or(page.getByText(/continue with email/i));
|
|
816
|
+
await emailBtn.first().waitFor({ state: "visible", timeout: 15e3 });
|
|
817
|
+
await emailBtn.first().click();
|
|
818
|
+
await page.waitForURL(
|
|
819
|
+
(u) => {
|
|
820
|
+
const s = u.toString();
|
|
821
|
+
return isCognito(s) || !isAppLoginPath(s) && !/\/auth\/callback/.test(pathOf(s));
|
|
822
|
+
},
|
|
823
|
+
{ timeout: timeoutMs }
|
|
824
|
+
);
|
|
825
|
+
if (isCognito(page.url())) {
|
|
826
|
+
await page.waitForLoadState("domcontentloaded");
|
|
827
|
+
log(`cognito ${page.url()}`);
|
|
828
|
+
const fillFirst = async (sels, val, what) => {
|
|
829
|
+
for (const s of sels) {
|
|
830
|
+
const loc = page.locator(s);
|
|
831
|
+
const n = await loc.count().catch(() => 0);
|
|
832
|
+
for (let i = 0; i < n; i++) {
|
|
833
|
+
const el = loc.nth(i);
|
|
834
|
+
if (await el.isVisible().catch(() => false)) {
|
|
835
|
+
await el.fill(val, { timeout: 1e4 });
|
|
836
|
+
log(`filled ${what} via ${s} [visible #${i}]`);
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
throw new Error(`Cognito ${what} field (visible) not found (selectors: ${sels.join(", ")})`);
|
|
842
|
+
};
|
|
843
|
+
await fillFirst(
|
|
844
|
+
[
|
|
845
|
+
"#signInFormUsername",
|
|
846
|
+
'input[name="username"]',
|
|
847
|
+
'input[type="email"]',
|
|
848
|
+
'input[autocomplete="username"]'
|
|
849
|
+
],
|
|
850
|
+
email,
|
|
851
|
+
"email"
|
|
852
|
+
);
|
|
853
|
+
await fillFirst(
|
|
854
|
+
[
|
|
855
|
+
"#signInFormPassword",
|
|
856
|
+
'input[name="password"]',
|
|
857
|
+
'input[type="password"]',
|
|
858
|
+
'input[autocomplete="current-password"]'
|
|
859
|
+
],
|
|
860
|
+
password,
|
|
861
|
+
"password"
|
|
862
|
+
);
|
|
863
|
+
const submitLoc = page.locator(
|
|
864
|
+
'input[name="signInSubmitButton"], button[type="submit"], input[type="submit"], [name="signInSubmitButton"]'
|
|
865
|
+
);
|
|
866
|
+
let clicked = false;
|
|
867
|
+
const sn = await submitLoc.count().catch(() => 0);
|
|
868
|
+
for (let i = 0; i < sn; i++) {
|
|
869
|
+
const el = submitLoc.nth(i);
|
|
870
|
+
if (await el.isVisible().catch(() => false)) {
|
|
871
|
+
await el.click();
|
|
872
|
+
clicked = true;
|
|
873
|
+
log(`clicked submit [visible #${i}]`);
|
|
874
|
+
break;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
if (!clicked) {
|
|
878
|
+
await page.getByRole("button", { name: /sign in|log in|continue|submit/i }).first().click();
|
|
879
|
+
log("clicked submit [role fallback]");
|
|
880
|
+
}
|
|
881
|
+
try {
|
|
882
|
+
await page.waitForURL(
|
|
883
|
+
(u) => {
|
|
884
|
+
const s = u.toString();
|
|
885
|
+
return !isCognito(s) && !/\/auth\/callback/.test(pathOf(s));
|
|
886
|
+
},
|
|
887
|
+
{ timeout: timeoutMs }
|
|
888
|
+
);
|
|
889
|
+
} catch {
|
|
890
|
+
const errorText2 = await scrapeErrorCard(page);
|
|
891
|
+
const finalUrl2 = page.url();
|
|
892
|
+
log(`stalled ${finalUrl2}`);
|
|
893
|
+
return { ok: false, finalUrl: finalUrl2, landingPath: pathOf(finalUrl2), errorText: errorText2 };
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
await page.waitForLoadState("networkidle").catch(() => {
|
|
897
|
+
});
|
|
898
|
+
await page.waitForFunction(
|
|
899
|
+
() => window.__uiBridgeInjected?.ready === true,
|
|
900
|
+
{ timeout: 15e3 }
|
|
901
|
+
).catch(() => {
|
|
902
|
+
});
|
|
903
|
+
const finalUrl = page.url();
|
|
904
|
+
const landingPath = await page.evaluate(() => location.pathname).catch(() => pathOf(finalUrl));
|
|
905
|
+
const ok = !isAppLoginPath(finalUrl) && !isCognito(finalUrl) && !/\/auth\/callback/.test(pathOf(finalUrl));
|
|
906
|
+
log(ok ? `authed ${finalUrl}` : `stalled ${finalUrl}`);
|
|
907
|
+
const errorText = ok ? null : await scrapeErrorCard(page);
|
|
908
|
+
return { ok, finalUrl, landingPath, errorText };
|
|
909
|
+
}
|
|
910
|
+
|
|
689
911
|
// src/login-web-cli.ts
|
|
690
912
|
var USAGE = `ui-bridge-login-web \u2014 automated web login via the UI Bridge injected transport
|
|
691
913
|
|
|
@@ -705,8 +927,19 @@ Options:
|
|
|
705
927
|
--post-login-click <css> Click this selector ONCE on the authed landing
|
|
706
928
|
(e.g. [data-testid='co-pilot-consent-allow']).
|
|
707
929
|
Non-fatal when the target never appears.
|
|
930
|
+
--expect-text <comma-list> Assert the authed page's body text contains EVERY
|
|
931
|
+
comma-separated entry. Missing entries fail the
|
|
932
|
+
exit code; the result JSON lists expectFound /
|
|
933
|
+
expectMissing. Matched case-sensitively.
|
|
934
|
+
--scroll-to <text> Before screenshotting, scroll the first element
|
|
935
|
+
containing this text into view (non-fatal if absent).
|
|
936
|
+
--screenshot <path> Write a full-page PNG of the authed landing to
|
|
937
|
+
<path> (captured BEFORE the --expect-text check, so
|
|
938
|
+
a failing assertion still leaves a diagnostic image).
|
|
708
939
|
--keep-open On success, park the authed session until SIGINT/
|
|
709
940
|
SIGTERM instead of closing the browser.
|
|
941
|
+
--quiet Suppress human-readable stderr logs (the JSON
|
|
942
|
+
result line still prints).
|
|
710
943
|
--help, -h Print this help and exit.
|
|
711
944
|
|
|
712
945
|
Prerequisites (packaged bin): the optional @qontinui/ui-bridge-headless peer must
|
|
@@ -719,6 +952,9 @@ Examples:
|
|
|
719
952
|
--success /build/workflows
|
|
720
953
|
ui-bridge-login-web --url "https://qontinui.io/login?next=%2Fco-pilot" \\
|
|
721
954
|
--success /co-pilot --post-login-click "[data-testid='co-pilot-consent-allow']" --keep-open
|
|
955
|
+
ui-bridge-login-web --url "https://qontinui.io/login?next=%2Foperations" \\
|
|
956
|
+
--success /operations --expect-text "option2-actions-outage-drill,metric_threshold" \\
|
|
957
|
+
--screenshot out.png
|
|
722
958
|
`;
|
|
723
959
|
var LoginCliArgError = class extends Error {
|
|
724
960
|
constructor(message) {
|
|
@@ -726,27 +962,11 @@ var LoginCliArgError = class extends Error {
|
|
|
726
962
|
this.name = "LoginCliArgError";
|
|
727
963
|
}
|
|
728
964
|
};
|
|
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
965
|
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
|
-
}
|
|
966
|
+
const mkError = (m) => new LoginCliArgError(m);
|
|
967
|
+
const reader = new ArgReader(argv, KNOWN_FLAGS, mkError);
|
|
968
|
+
const valueOf = (name) => reader.value(name);
|
|
969
|
+
const has = (name) => reader.has(name);
|
|
750
970
|
const help = has("--help") || has("-h");
|
|
751
971
|
const timeoutRaw = valueOf("--timeout");
|
|
752
972
|
const timeoutMs = timeoutRaw === null ? 6e4 : Number.parseInt(timeoutRaw, 10);
|
|
@@ -754,14 +974,20 @@ function parseArgs(argv) {
|
|
|
754
974
|
throw new LoginCliArgError(`--timeout expects a positive integer (got ${timeoutRaw})`);
|
|
755
975
|
}
|
|
756
976
|
const args = {
|
|
757
|
-
url: valueOf("--url") ?? "https://qontinui.io/login",
|
|
977
|
+
url: rejectEmptyValue("--url", valueOf("--url"), mkError) ?? "https://qontinui.io/login",
|
|
758
978
|
email: valueOf("--email") ?? process.env.UIB_LOGIN_EMAIL ?? "",
|
|
759
979
|
password: valueOf("--password") ?? process.env.UIB_LOGIN_PASSWORD ?? "",
|
|
760
|
-
success
|
|
980
|
+
// An EMPTY --success would make `landingPath.includes('')` true on any
|
|
981
|
+
// landing — ok:true while parked on the login page. Reject it.
|
|
982
|
+
success: rejectEmptyValue("--success", valueOf("--success"), mkError) ?? "/dashboard",
|
|
761
983
|
timeoutMs,
|
|
762
984
|
headed: has("--headed"),
|
|
763
985
|
postClick: valueOf("--post-login-click"),
|
|
986
|
+
expectText: (valueOf("--expect-text") ?? "").split(",").map((s) => s.trim()).filter((s) => s.length > 0),
|
|
987
|
+
scrollToText: valueOf("--scroll-to"),
|
|
988
|
+
screenshotPath: valueOf("--screenshot"),
|
|
764
989
|
keepOpen: has("--keep-open"),
|
|
990
|
+
quiet: has("--quiet"),
|
|
765
991
|
help
|
|
766
992
|
};
|
|
767
993
|
validateArgs(args);
|
|
@@ -775,9 +1001,11 @@ var KNOWN_FLAGS = /* @__PURE__ */ new Set([
|
|
|
775
1001
|
"--timeout",
|
|
776
1002
|
"--headed",
|
|
777
1003
|
"--post-login-click",
|
|
1004
|
+
"--expect-text",
|
|
1005
|
+
"--scroll-to",
|
|
1006
|
+
"--screenshot",
|
|
778
1007
|
"--keep-open",
|
|
779
|
-
|
|
780
|
-
"-h"
|
|
1008
|
+
...COMMON_FLAGS
|
|
781
1009
|
]);
|
|
782
1010
|
function validateArgs(args) {
|
|
783
1011
|
if (args.help) return;
|
|
@@ -790,10 +1018,6 @@ function validateArgs(args) {
|
|
|
790
1018
|
);
|
|
791
1019
|
}
|
|
792
1020
|
}
|
|
793
|
-
function log(m) {
|
|
794
|
-
process.stderr.write(`[login-web] ${m}
|
|
795
|
-
`);
|
|
796
|
-
}
|
|
797
1021
|
async function main() {
|
|
798
1022
|
let args;
|
|
799
1023
|
try {
|
|
@@ -811,87 +1035,19 @@ ${USAGE}`);
|
|
|
811
1035
|
process.stdout.write(USAGE);
|
|
812
1036
|
process.exit(0);
|
|
813
1037
|
}
|
|
814
|
-
const { url, email, password, success, timeoutMs, headed, postClick } = args;
|
|
1038
|
+
const { url, email, password, success, timeoutMs, headed, postClick, expectText, scrollToText, screenshotPath } = args;
|
|
1039
|
+
const log = makeLogger("[login-web]", args.quiet);
|
|
815
1040
|
const transport = createTransport({
|
|
816
1041
|
kind: "injected",
|
|
817
1042
|
options: { targetUrl: url, waitForSettle: false, readyTimeoutMs: 45e3, headed }
|
|
818
1043
|
});
|
|
819
1044
|
transport.register("drive", async (_p, ctx) => {
|
|
820
1045
|
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
|
-
}
|
|
1046
|
+
const r = await loginDrive(page, { email, password, timeoutMs, log });
|
|
1047
|
+
if (r.ok && !isSuccessPath(page.url(), success)) {
|
|
1048
|
+
await page.waitForURL((u) => isSuccessPath(u.toString(), success), { timeout: 1e4 }).catch(() => {
|
|
1049
|
+
});
|
|
892
1050
|
}
|
|
893
|
-
await page.waitForLoadState("networkidle").catch(() => {
|
|
894
|
-
});
|
|
895
1051
|
const finalUrl = page.url();
|
|
896
1052
|
log(`final ${finalUrl}`);
|
|
897
1053
|
await page.waitForFunction(() => window.__uiBridgeInjected?.ready === true, {
|
|
@@ -904,24 +1060,13 @@ ${USAGE}`);
|
|
|
904
1060
|
} catch {
|
|
905
1061
|
}
|
|
906
1062
|
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
|
-
}
|
|
1063
|
+
const landingPath = uiBridgeRoute ?? (finalUrl === r.finalUrl ? r.landingPath : pathOf(finalUrl));
|
|
1064
|
+
const onAppLoginPage = isAppLoginPath(finalUrl);
|
|
1065
|
+
const stillOnCognito = isCognito(finalUrl);
|
|
1066
|
+
const ok = !onAppLoginPage && !stillOnCognito && landingPath.includes(success);
|
|
1067
|
+
let errorText = r.errorText;
|
|
1068
|
+
if (!ok && !errorText) {
|
|
1069
|
+
errorText = await scrapeErrorCard(page);
|
|
925
1070
|
}
|
|
926
1071
|
let postLoginClicked = null;
|
|
927
1072
|
if (ok && postClick) {
|
|
@@ -936,16 +1081,41 @@ ${USAGE}`);
|
|
|
936
1081
|
log(`post-login click target never visible (non-fatal): ${postClick}`);
|
|
937
1082
|
}
|
|
938
1083
|
}
|
|
1084
|
+
let screenshotWritten = null;
|
|
1085
|
+
if (ok && screenshotPath) {
|
|
1086
|
+
try {
|
|
1087
|
+
if (scrollToText) {
|
|
1088
|
+
await page.getByText(scrollToText).first().scrollIntoViewIfNeeded({ timeout: 5e3 }).catch(() => log(`scroll-to target not found (non-fatal): ${scrollToText}`));
|
|
1089
|
+
}
|
|
1090
|
+
await page.screenshot({ path: screenshotPath, fullPage: true });
|
|
1091
|
+
screenshotWritten = screenshotPath;
|
|
1092
|
+
log(`screenshot written: ${screenshotPath}`);
|
|
1093
|
+
} catch (err) {
|
|
1094
|
+
log(`screenshot failed (non-fatal): ${err instanceof Error ? err.message : String(err)}`);
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
let expectFound;
|
|
1098
|
+
let expectMissing;
|
|
1099
|
+
if (ok && expectText.length > 0) {
|
|
1100
|
+
const body = await page.evaluate(() => document.body?.innerText ?? "").catch(() => "");
|
|
1101
|
+
expectFound = expectText.filter((t) => body.includes(t));
|
|
1102
|
+
expectMissing = expectText.filter((t) => !body.includes(t));
|
|
1103
|
+
if (expectMissing.length > 0) log(`expect-text missing: ${expectMissing.join(", ")}`);
|
|
1104
|
+
}
|
|
1105
|
+
const finalOk = ok && (expectMissing?.length ?? 0) === 0;
|
|
939
1106
|
return {
|
|
940
|
-
ok,
|
|
1107
|
+
ok: finalOk,
|
|
941
1108
|
finalUrl,
|
|
942
1109
|
landingPath,
|
|
943
|
-
onAppLoginPage
|
|
944
|
-
stillOnCognito
|
|
1110
|
+
onAppLoginPage,
|
|
1111
|
+
stillOnCognito,
|
|
945
1112
|
errorText,
|
|
946
1113
|
uiBridgeRoute,
|
|
947
1114
|
uiBridgeRegistered: snap?.registration?.totalRegistered ?? null,
|
|
948
|
-
postLoginClicked
|
|
1115
|
+
postLoginClicked,
|
|
1116
|
+
expectFound,
|
|
1117
|
+
expectMissing,
|
|
1118
|
+
screenshotPath: screenshotPath ? screenshotWritten : void 0
|
|
949
1119
|
};
|
|
950
1120
|
});
|
|
951
1121
|
let result;
|
|
@@ -994,11 +1164,7 @@ if (isMain) {
|
|
|
994
1164
|
|
|
995
1165
|
exports.LoginCliArgError = LoginCliArgError;
|
|
996
1166
|
exports.USAGE = USAGE;
|
|
997
|
-
exports.isAppLoginPath = isAppLoginPath;
|
|
998
|
-
exports.isCognito = isCognito;
|
|
999
|
-
exports.isSuccessPath = isSuccessPath;
|
|
1000
1167
|
exports.parseArgs = parseArgs;
|
|
1001
|
-
exports.pathOf = pathOf;
|
|
1002
1168
|
exports.validateArgs = validateArgs;
|
|
1003
1169
|
//# sourceMappingURL=login-web-cli.cjs.map
|
|
1004
1170
|
//# sourceMappingURL=login-web-cli.cjs.map
|