@qontinui/ui-bridge-wrapper 0.12.0 → 0.15.0
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 +157 -8
- package/dist/capture-specs-cli.cjs +301 -53
- package/dist/capture-specs-cli.cjs.map +1 -1
- package/dist/capture-specs-cli.d.ts.map +1 -1
- package/dist/chunk-IKHDNIU4.js +478 -0
- package/dist/chunk-IKHDNIU4.js.map +1 -0
- package/dist/chunk-Z32CC665.cjs +488 -0
- package/dist/chunk-Z32CC665.cjs.map +1 -0
- package/dist/create-transport.d.ts.map +1 -1
- package/dist/frame-capture.d.ts +3 -28
- package/dist/frame-capture.d.ts.map +1 -1
- package/dist/frame-page.d.ts +35 -0
- package/dist/frame-page.d.ts.map +1 -0
- package/dist/index.cjs +145 -375
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +90 -351
- package/dist/index.js.map +1 -1
- package/dist/inject-cli.cjs +407 -134
- package/dist/inject-cli.cjs.map +1 -1
- package/dist/inject-cli.d.ts +1 -1
- package/dist/inject-cli.d.ts.map +1 -1
- package/dist/live/index.cjs +40 -0
- package/dist/live/index.cjs.map +1 -0
- package/dist/live/index.d.ts +32 -0
- package/dist/live/index.d.ts.map +1 -0
- package/dist/live/index.js +3 -0
- package/dist/live/index.js.map +1 -0
- package/dist/login-web-cli.cjs +312 -61
- package/dist/login-web-cli.cjs.map +1 -1
- package/dist/login-web-cli.d.ts.map +1 -1
- package/dist/network-throttle.d.ts +5 -0
- package/dist/network-throttle.d.ts.map +1 -1
- package/dist/screenshot-capture.d.ts +82 -0
- package/dist/screenshot-capture.d.ts.map +1 -0
- package/dist/timeline-capture.d.ts +74 -10
- package/dist/timeline-capture.d.ts.map +1 -1
- package/dist/transports/headless.d.ts +46 -1
- package/dist/transports/headless.d.ts.map +1 -1
- package/dist/transports/injected.d.ts +8 -0
- package/dist/transports/injected.d.ts.map +1 -1
- package/dist/transports/live.d.ts +27 -1
- package/dist/transports/live.d.ts.map +1 -1
- package/dist/types.d.ts +3 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +11 -8
- package/dist/cli-args.d.ts +0 -13
- package/dist/cli-args.d.ts.map +0 -1
package/dist/login-web-cli.cjs
CHANGED
|
@@ -4,48 +4,14 @@
|
|
|
4
4
|
var fs = require('fs');
|
|
5
5
|
var module$1 = require('module');
|
|
6
6
|
var crypto = require('crypto');
|
|
7
|
-
var ui_bridge_cli_args_star = require('@qontinui/ui-bridge-cli-args');
|
|
8
7
|
|
|
9
8
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
10
|
-
function _interopNamespace(e) {
|
|
11
|
-
if (e && e.__esModule) return e;
|
|
12
|
-
var n = Object.create(null);
|
|
13
|
-
if (e) {
|
|
14
|
-
Object.keys(e).forEach(function (k) {
|
|
15
|
-
if (k !== 'default') {
|
|
16
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function () { return e[k]; }
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
n.default = e;
|
|
25
|
-
return Object.freeze(n);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
var ui_bridge_cli_args_star__namespace = /*#__PURE__*/_interopNamespace(ui_bridge_cli_args_star);
|
|
29
|
-
|
|
30
|
-
var __defProp = Object.defineProperty;
|
|
31
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
32
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
33
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
34
9
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
35
10
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
36
11
|
}) : x)(function(x) {
|
|
37
12
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
38
13
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
39
14
|
});
|
|
40
|
-
var __copyProps = (to, from, except, desc) => {
|
|
41
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
42
|
-
for (let key of __getOwnPropNames(from))
|
|
43
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
44
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
45
|
-
}
|
|
46
|
-
return to;
|
|
47
|
-
};
|
|
48
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget);
|
|
49
15
|
|
|
50
16
|
// src/types.ts
|
|
51
17
|
var WrapperTransportError = class extends Error {
|
|
@@ -279,9 +245,60 @@ var HeadlessTransport = class extends BaseTransport {
|
|
|
279
245
|
userAgent: typeof raw["userAgent"] === "string" ? raw["userAgent"] : void 0,
|
|
280
246
|
forwardConsole: typeof raw["forwardConsole"] === "boolean" ? raw["forwardConsole"] : void 0,
|
|
281
247
|
launchArgs: Array.isArray(raw["launchArgs"]) && raw["launchArgs"].every((a) => typeof a === "string") ? raw["launchArgs"] : void 0,
|
|
282
|
-
storageStatePath: typeof raw["storageStatePath"] === "string" ? raw["storageStatePath"] : void 0
|
|
248
|
+
storageStatePath: typeof raw["storageStatePath"] === "string" ? raw["storageStatePath"] : void 0,
|
|
249
|
+
...this.parseContextOptions(raw)
|
|
283
250
|
};
|
|
284
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* `recordHar`, `recordVideo`, `serviceWorkers` and `initRouter`. Unlike the display
|
|
254
|
+
* options above, a malformed value is REFUSED rather than dropped: dropping
|
|
255
|
+
* `recordHar` would leave a caller waiting for an archive that is never
|
|
256
|
+
* written, and dropping `initRouter` would let requests it meant to answer
|
|
257
|
+
* reach the network.
|
|
258
|
+
*/
|
|
259
|
+
parseContextOptions(raw) {
|
|
260
|
+
const out = {};
|
|
261
|
+
const invalid = (what) => new WrapperTransportError("INVALID_CONFIG", `Transport kind '${this.kind}': ${what}`);
|
|
262
|
+
const har = raw["recordHar"];
|
|
263
|
+
if (har !== void 0) {
|
|
264
|
+
if (typeof har !== "object" || har === null || typeof har.path !== "string" || har.path.length === 0) {
|
|
265
|
+
throw invalid("options.recordHar must be an object with a non-empty string `path`");
|
|
266
|
+
}
|
|
267
|
+
out.recordHar = har;
|
|
268
|
+
}
|
|
269
|
+
const video = raw["recordVideo"];
|
|
270
|
+
if (video !== void 0) {
|
|
271
|
+
if (typeof video !== "object" || video === null || typeof video.dir !== "string" || video.dir.length === 0) {
|
|
272
|
+
throw invalid("options.recordVideo must be an object with a non-empty string `dir`");
|
|
273
|
+
}
|
|
274
|
+
const size = video.size;
|
|
275
|
+
if (size !== void 0) {
|
|
276
|
+
const positiveInt = (n) => typeof n === "number" && Number.isInteger(n) && n > 0;
|
|
277
|
+
const s = size;
|
|
278
|
+
if (typeof size !== "object" || s === null || !positiveInt(s.width) || !positiveInt(s.height)) {
|
|
279
|
+
throw invalid(
|
|
280
|
+
"options.recordVideo.size must be { width, height } with positive integer sides"
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
out.recordVideo = video;
|
|
285
|
+
}
|
|
286
|
+
const sw = raw["serviceWorkers"];
|
|
287
|
+
if (sw !== void 0) {
|
|
288
|
+
if (sw !== "allow" && sw !== "block") {
|
|
289
|
+
throw invalid(`options.serviceWorkers must be 'allow' or 'block' (got ${String(sw)})`);
|
|
290
|
+
}
|
|
291
|
+
out.serviceWorkers = sw;
|
|
292
|
+
}
|
|
293
|
+
const router = raw["initRouter"];
|
|
294
|
+
if (router !== void 0) {
|
|
295
|
+
if (typeof router !== "function") {
|
|
296
|
+
throw invalid("options.initRouter must be a function (context) => void | Promise<void>");
|
|
297
|
+
}
|
|
298
|
+
out.initRouter = router;
|
|
299
|
+
}
|
|
300
|
+
return out;
|
|
301
|
+
}
|
|
285
302
|
async onReady() {
|
|
286
303
|
let launchHeadlessTab;
|
|
287
304
|
const headlessSpecifier = "@qontinui/ui-bridge-headless";
|
|
@@ -309,6 +326,13 @@ Underlying import error: ${cause}`
|
|
|
309
326
|
const initScripts = await this.buildInitScripts();
|
|
310
327
|
const relayAuth = this.relayAuth();
|
|
311
328
|
const pinnedTabId = this.pinnedTabId();
|
|
329
|
+
const { recordHar, recordVideo, serviceWorkers, initRouter: callerRouter } = this.options;
|
|
330
|
+
const contextOptionsRequested = recordHar !== void 0 || recordVideo !== void 0 || serviceWorkers === "block" || callerRouter !== void 0;
|
|
331
|
+
let routerCalled = false;
|
|
332
|
+
const initRouter = contextOptionsRequested || serviceWorkers !== void 0 ? async (context) => {
|
|
333
|
+
routerCalled = true;
|
|
334
|
+
if (callerRouter) await callerRouter(context);
|
|
335
|
+
} : void 0;
|
|
312
336
|
let tab;
|
|
313
337
|
try {
|
|
314
338
|
tab = await launchHeadlessTab({
|
|
@@ -327,7 +351,11 @@ Underlying import error: ${cause}`
|
|
|
327
351
|
storageStatePath: this.options.storageStatePath,
|
|
328
352
|
...relayAuth.authToken ? { authToken: relayAuth.authToken } : {},
|
|
329
353
|
...relayAuth.callerUserId ? { callerUserId: relayAuth.callerUserId } : {},
|
|
330
|
-
...pinnedTabId ? { pinnedTabId } : {}
|
|
354
|
+
...pinnedTabId ? { pinnedTabId } : {},
|
|
355
|
+
...recordHar !== void 0 ? { recordHar } : {},
|
|
356
|
+
...recordVideo !== void 0 ? { recordVideo } : {},
|
|
357
|
+
...serviceWorkers !== void 0 ? { serviceWorkers } : {},
|
|
358
|
+
...initRouter ? { initRouter } : {}
|
|
331
359
|
});
|
|
332
360
|
} catch (err) {
|
|
333
361
|
const cause = err instanceof Error ? err.message : String(err);
|
|
@@ -349,6 +377,24 @@ Underlying launch error: ${cause}`
|
|
|
349
377
|
tabId: tab.tabId,
|
|
350
378
|
close: tab.close
|
|
351
379
|
};
|
|
380
|
+
if (contextOptionsRequested && !routerCalled) {
|
|
381
|
+
await this.onClose().catch(() => {
|
|
382
|
+
});
|
|
383
|
+
throw new WrapperTransportError(
|
|
384
|
+
"CONTEXT_OPTIONS_NOT_APPLIED",
|
|
385
|
+
`The installed '@qontinui/ui-bridge-headless' peer launched the tab without calling initRouter, so it predates the recordHar / recordVideo / serviceWorkers / initRouter passthrough (0.8.0, ui-bridge#381) and ignored them: no HAR or video would be written and no route installed. Upgrade it to 0.8.0 or later.`,
|
|
386
|
+
{
|
|
387
|
+
details: {
|
|
388
|
+
requested: {
|
|
389
|
+
recordHar: recordHar !== void 0,
|
|
390
|
+
recordVideo: recordVideo !== void 0,
|
|
391
|
+
serviceWorkers: serviceWorkers ?? null,
|
|
392
|
+
initRouter: callerRouter !== void 0
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
);
|
|
397
|
+
}
|
|
352
398
|
await this.verifyEmulation(tab.page);
|
|
353
399
|
await this.afterLaunch(tab.page);
|
|
354
400
|
}
|
|
@@ -695,6 +741,7 @@ var InjectedTransport = class extends HeadlessTransport {
|
|
|
695
741
|
execute,
|
|
696
742
|
find: (criteria) => execute("find", criteria ?? {}),
|
|
697
743
|
act: (id, request) => execute("executeElementAction", { id, request }),
|
|
744
|
+
element: (id) => execute("getElement", { id }),
|
|
698
745
|
snapshot: (options) => execute("getControlSnapshot", options ?? {}),
|
|
699
746
|
assert: (spec) => execute("aiAssert", spec)
|
|
700
747
|
};
|
|
@@ -706,6 +753,113 @@ function isRegistrationMetadata(value) {
|
|
|
706
753
|
return typeof v.userId === "string" && typeof v.sessionId === "string";
|
|
707
754
|
}
|
|
708
755
|
|
|
756
|
+
// src/frame-page.ts
|
|
757
|
+
var PNG_SIGNATURE = [137, 80, 78, 71, 13, 10, 26, 10];
|
|
758
|
+
function pngDimensions(buf) {
|
|
759
|
+
if (buf.length < 24 || PNG_SIGNATURE.some((b, i) => buf[i] !== b)) {
|
|
760
|
+
throw new Error("not a PNG (signature mismatch or truncated header)");
|
|
761
|
+
}
|
|
762
|
+
const chunkType = String.fromCharCode(buf[12], buf[13], buf[14], buf[15]);
|
|
763
|
+
if (chunkType !== "IHDR") {
|
|
764
|
+
throw new Error(`PNG does not start with an IHDR chunk (found ${JSON.stringify(chunkType)})`);
|
|
765
|
+
}
|
|
766
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
767
|
+
return { width: view.getUint32(16), height: view.getUint32(20) };
|
|
768
|
+
}
|
|
769
|
+
async function readPageMetrics(page) {
|
|
770
|
+
return page.evaluate(() => ({
|
|
771
|
+
devicePixelRatio: window.devicePixelRatio,
|
|
772
|
+
innerWidth: window.innerWidth,
|
|
773
|
+
innerHeight: window.innerHeight,
|
|
774
|
+
colorScheme: window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"
|
|
775
|
+
}));
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
// src/screenshot-capture.ts
|
|
779
|
+
var SCREENSHOT_CAPABILITY = "screenshot";
|
|
780
|
+
var SCREENSHOT_ACTION = "getScreenshot";
|
|
781
|
+
var SCREENSHOT_TIMEOUT_MS = 1e4;
|
|
782
|
+
var NO_COMPOSITOR_FRAME = /Unable to capture screenshot/;
|
|
783
|
+
var NO_COMPOSITOR_FRAME_RETRY_MS = 16;
|
|
784
|
+
function toBase64(bytes) {
|
|
785
|
+
const CHUNK = 32768;
|
|
786
|
+
let binary = "";
|
|
787
|
+
for (let i = 0; i < bytes.length; i += CHUNK) {
|
|
788
|
+
binary += String.fromCharCode(...bytes.subarray(i, i + CHUNK));
|
|
789
|
+
}
|
|
790
|
+
return btoa(binary);
|
|
791
|
+
}
|
|
792
|
+
function errorText(err) {
|
|
793
|
+
return err instanceof Error ? err.message : String(err);
|
|
794
|
+
}
|
|
795
|
+
async function captureScreenshotReply(page, options = {}) {
|
|
796
|
+
const timeoutMs = options.timeoutMs ?? SCREENSHOT_TIMEOUT_MS;
|
|
797
|
+
const retryMs = options.retryMs ?? NO_COMPOSITOR_FRAME_RETRY_MS;
|
|
798
|
+
const deadline = Date.now() + timeoutMs;
|
|
799
|
+
let timedOut = false;
|
|
800
|
+
let timer;
|
|
801
|
+
const attempt = async () => {
|
|
802
|
+
let metrics;
|
|
803
|
+
try {
|
|
804
|
+
metrics = await readPageMetrics(page);
|
|
805
|
+
} catch (err) {
|
|
806
|
+
throw new WrapperTransportError(
|
|
807
|
+
"SCREENSHOT_FAILED",
|
|
808
|
+
`could not read the page's viewport: ${errorText(err)}`,
|
|
809
|
+
{ cause: err }
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
for (; ; ) {
|
|
813
|
+
let png;
|
|
814
|
+
try {
|
|
815
|
+
png = await page.screenshot({ type: "png", scale: "device", fullPage: false });
|
|
816
|
+
} catch (err) {
|
|
817
|
+
const text = errorText(err);
|
|
818
|
+
const noFrameYet = NO_COMPOSITOR_FRAME.test(text);
|
|
819
|
+
if (noFrameYet && !timedOut && Date.now() + retryMs < deadline) {
|
|
820
|
+
await new Promise((r) => setTimeout(r, retryMs));
|
|
821
|
+
if (timedOut) throw err;
|
|
822
|
+
continue;
|
|
823
|
+
}
|
|
824
|
+
throw new WrapperTransportError("SCREENSHOT_FAILED", `screenshot failed: ${text}`, {
|
|
825
|
+
retryable: noFrameYet,
|
|
826
|
+
cause: err
|
|
827
|
+
});
|
|
828
|
+
}
|
|
829
|
+
try {
|
|
830
|
+
pngDimensions(png);
|
|
831
|
+
} catch (err) {
|
|
832
|
+
throw new WrapperTransportError(
|
|
833
|
+
"SCREENSHOT_FAILED",
|
|
834
|
+
`the screenshot is unreadable: ${errorText(err)}`,
|
|
835
|
+
{ cause: err }
|
|
836
|
+
);
|
|
837
|
+
}
|
|
838
|
+
return { screenshot: toBase64(png), width: metrics.innerWidth, height: metrics.innerHeight };
|
|
839
|
+
}
|
|
840
|
+
};
|
|
841
|
+
const timeout = new Promise((_, reject) => {
|
|
842
|
+
timer = setTimeout(() => {
|
|
843
|
+
timedOut = true;
|
|
844
|
+
reject(
|
|
845
|
+
new WrapperTransportError(
|
|
846
|
+
"SCREENSHOT_TIMEOUT",
|
|
847
|
+
`screenshot did not complete within ${timeoutMs}ms`,
|
|
848
|
+
{ retryable: true }
|
|
849
|
+
)
|
|
850
|
+
);
|
|
851
|
+
}, timeoutMs);
|
|
852
|
+
});
|
|
853
|
+
try {
|
|
854
|
+
return await Promise.race([attempt(), timeout]);
|
|
855
|
+
} finally {
|
|
856
|
+
clearTimeout(timer);
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
function registerScreenshotCapture(registrar, page, options = {}) {
|
|
860
|
+
registrar.register(SCREENSHOT_ACTION, () => captureScreenshotReply(page, options));
|
|
861
|
+
}
|
|
862
|
+
|
|
709
863
|
// src/transports/live.ts
|
|
710
864
|
var LiveSessionTransport = class extends BaseTransport {
|
|
711
865
|
kind = "live";
|
|
@@ -725,6 +879,16 @@ var LiveSessionTransport = class extends BaseTransport {
|
|
|
725
879
|
this.appId = config.appId;
|
|
726
880
|
this.appName = config.appName;
|
|
727
881
|
this.opts = config.options ?? {};
|
|
882
|
+
const page = this.opts.screenshotPage;
|
|
883
|
+
if (page !== void 0) {
|
|
884
|
+
if (page === null || typeof page.screenshot !== "function" || typeof page.evaluate !== "function") {
|
|
885
|
+
throw new WrapperTransportError(
|
|
886
|
+
"INVALID_CONFIG",
|
|
887
|
+
`options.screenshotPage must expose screenshot() and evaluate() (a Playwright Page does)`
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
registerScreenshotCapture(this.registry, page);
|
|
891
|
+
}
|
|
728
892
|
const fromInjection = injected?.webSocketCtor;
|
|
729
893
|
const fromGlobal = typeof globalThis.WebSocket === "function" ? globalThis.WebSocket : void 0;
|
|
730
894
|
const resolved = fromInjection ?? fromGlobal;
|
|
@@ -754,7 +918,8 @@ var LiveSessionTransport = class extends BaseTransport {
|
|
|
754
918
|
};
|
|
755
919
|
if (this.opts.framework !== void 0) frame.framework = this.opts.framework;
|
|
756
920
|
if (this.opts.version !== void 0) frame.version = this.opts.version;
|
|
757
|
-
|
|
921
|
+
const capabilities = this.advertisedCapabilities();
|
|
922
|
+
if (capabilities !== void 0) frame.capabilities = capabilities;
|
|
758
923
|
if (this.opts.origin !== void 0) frame.origin = this.opts.origin;
|
|
759
924
|
if (this.opts.pageUrl !== void 0) frame.pageUrl = this.opts.pageUrl;
|
|
760
925
|
ws.send(JSON.stringify(frame));
|
|
@@ -794,6 +959,18 @@ var LiveSessionTransport = class extends BaseTransport {
|
|
|
794
959
|
}
|
|
795
960
|
}
|
|
796
961
|
}
|
|
962
|
+
/**
|
|
963
|
+
* The register frame's `capabilities`: the caller's list, plus
|
|
964
|
+
* `"screenshot"` exactly when this transport registered the handler for it.
|
|
965
|
+
* `undefined` (field omitted) when there is nothing to advertise.
|
|
966
|
+
*/
|
|
967
|
+
advertisedCapabilities() {
|
|
968
|
+
const declared = this.opts.capabilities;
|
|
969
|
+
if (this.opts.screenshotPage === void 0) return declared;
|
|
970
|
+
const list = [...declared ?? []];
|
|
971
|
+
if (!list.includes(SCREENSHOT_CAPABILITY)) list.push(SCREENSHOT_CAPABILITY);
|
|
972
|
+
return list;
|
|
973
|
+
}
|
|
797
974
|
async buildContext() {
|
|
798
975
|
return { kind: "live", commandId: null };
|
|
799
976
|
}
|
|
@@ -958,9 +1135,88 @@ function mergeMultiOriginSessionStorageIntoArtifact(artifact, map) {
|
|
|
958
1135
|
return artifact;
|
|
959
1136
|
}
|
|
960
1137
|
|
|
961
|
-
//
|
|
962
|
-
var
|
|
963
|
-
|
|
1138
|
+
// ../ui-bridge-cli-args/dist/index.js
|
|
1139
|
+
var COMMON_FLAGS = /* @__PURE__ */ new Set(["--help", "-h", "--quiet"]);
|
|
1140
|
+
function isFlagShaped(value) {
|
|
1141
|
+
return value.startsWith("--");
|
|
1142
|
+
}
|
|
1143
|
+
function consumeValue(flag, raw, error) {
|
|
1144
|
+
if (raw === void 0) return null;
|
|
1145
|
+
if (isFlagShaped(raw)) {
|
|
1146
|
+
throw error(
|
|
1147
|
+
`${flag} expects a value but got the flag '${raw}' \u2014 did you omit ${flag}'s argument?`
|
|
1148
|
+
);
|
|
1149
|
+
}
|
|
1150
|
+
return raw;
|
|
1151
|
+
}
|
|
1152
|
+
function rejectEmptyValue(flag, value, error) {
|
|
1153
|
+
if (value !== null && value.trim() === "") {
|
|
1154
|
+
throw error(
|
|
1155
|
+
`${flag} was given an empty value \u2014 omit the flag to use its default, or pass a non-empty value`
|
|
1156
|
+
);
|
|
1157
|
+
}
|
|
1158
|
+
return value;
|
|
1159
|
+
}
|
|
1160
|
+
function parsePositiveInt(flag, raw, error) {
|
|
1161
|
+
const n = raw !== null && /^\d+$/.test(raw) ? Number(raw) : NaN;
|
|
1162
|
+
if (!Number.isSafeInteger(n) || n <= 0) {
|
|
1163
|
+
throw error(`${flag} expects a positive integer (got ${raw ?? "<missing>"})`);
|
|
1164
|
+
}
|
|
1165
|
+
return n;
|
|
1166
|
+
}
|
|
1167
|
+
var ArgReader = class {
|
|
1168
|
+
argv;
|
|
1169
|
+
error;
|
|
1170
|
+
valueFlags;
|
|
1171
|
+
/**
|
|
1172
|
+
* @param argv Already sliced past `node script`.
|
|
1173
|
+
* @param known All flags the bin recognizes (union the bin's set with {@link COMMON_FLAGS}).
|
|
1174
|
+
* @param error Factory producing the bin's domain error type.
|
|
1175
|
+
* @param valueFlags The flags that take a value. The token after one is that
|
|
1176
|
+
* flag's value, never a flag of its own, so `--success -h`
|
|
1177
|
+
* does not also ask for help. Without it, {@link has} cannot
|
|
1178
|
+
* tell a value from a flag.
|
|
1179
|
+
*/
|
|
1180
|
+
constructor(argv, known, error, valueFlags = /* @__PURE__ */ new Set()) {
|
|
1181
|
+
this.argv = argv;
|
|
1182
|
+
this.error = error;
|
|
1183
|
+
this.valueFlags = valueFlags;
|
|
1184
|
+
for (const arg of argv) {
|
|
1185
|
+
if (isFlagShaped(arg) && !known.has(arg)) {
|
|
1186
|
+
throw error(`Unknown flag: ${arg}`);
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
/** True if `name` appears as a bare boolean flag, not as a value-flag's value. */
|
|
1191
|
+
has(name) {
|
|
1192
|
+
for (let i = 0; i < this.argv.length; i++) {
|
|
1193
|
+
if (this.valueFlags.has(this.argv[i])) {
|
|
1194
|
+
i++;
|
|
1195
|
+
continue;
|
|
1196
|
+
}
|
|
1197
|
+
if (this.argv[i] === name) return true;
|
|
1198
|
+
}
|
|
1199
|
+
return false;
|
|
1200
|
+
}
|
|
1201
|
+
/**
|
|
1202
|
+
* Value following the value-flag `name`, or `null` when the flag is absent OR
|
|
1203
|
+
* has no following token (the caller defaults it). Throws when the following
|
|
1204
|
+
* token is flag-shaped — the swallow this kit exists to kill. Delegates to
|
|
1205
|
+
* {@link consumeValue} so the guard (and its message) live in exactly one
|
|
1206
|
+
* place for both the indexOf-style and switch-style parsers.
|
|
1207
|
+
*/
|
|
1208
|
+
value(name) {
|
|
1209
|
+
const i = this.argv.indexOf(name);
|
|
1210
|
+
if (i < 0 || i + 1 >= this.argv.length) return null;
|
|
1211
|
+
return consumeValue(name, this.argv[i + 1], this.error);
|
|
1212
|
+
}
|
|
1213
|
+
};
|
|
1214
|
+
function makeLogger(prefix, quiet) {
|
|
1215
|
+
if (quiet) return () => {
|
|
1216
|
+
};
|
|
1217
|
+
return (m) => process.stderr.write(`${prefix} ${m}
|
|
1218
|
+
`) ;
|
|
1219
|
+
}
|
|
964
1220
|
|
|
965
1221
|
// src/action-outcome.ts
|
|
966
1222
|
function isRecord(v) {
|
|
@@ -1076,10 +1332,10 @@ async function loginDrive(page, { email, password, timeoutMs, log = () => {
|
|
|
1076
1332
|
{ timeout: timeoutMs }
|
|
1077
1333
|
);
|
|
1078
1334
|
} catch {
|
|
1079
|
-
const
|
|
1335
|
+
const errorText3 = await scrapeErrorCard(page);
|
|
1080
1336
|
const finalUrl2 = page.url();
|
|
1081
1337
|
log(`stalled ${finalUrl2}`);
|
|
1082
|
-
return { ok: false, finalUrl: finalUrl2, landingPath: pathOf(finalUrl2), errorText:
|
|
1338
|
+
return { ok: false, finalUrl: finalUrl2, landingPath: pathOf(finalUrl2), errorText: errorText3 };
|
|
1083
1339
|
}
|
|
1084
1340
|
}
|
|
1085
1341
|
await page.waitForLoadState("networkidle").catch(() => {
|
|
@@ -1093,8 +1349,8 @@ async function loginDrive(page, { email, password, timeoutMs, log = () => {
|
|
|
1093
1349
|
const landingPath = await page.evaluate(() => location.pathname).catch(() => pathOf(finalUrl));
|
|
1094
1350
|
const ok = !isAppLoginPath(finalUrl) && !isCognito(finalUrl) && !/\/auth\/callback/.test(pathOf(finalUrl));
|
|
1095
1351
|
log(ok ? `authed ${finalUrl}` : `stalled ${finalUrl}`);
|
|
1096
|
-
const
|
|
1097
|
-
return { ok, finalUrl, landingPath, errorText };
|
|
1352
|
+
const errorText2 = ok ? null : await scrapeErrorCard(page);
|
|
1353
|
+
return { ok, finalUrl, landingPath, errorText: errorText2 };
|
|
1098
1354
|
}
|
|
1099
1355
|
|
|
1100
1356
|
// src/login-web-cli.ts
|
|
@@ -1166,22 +1422,19 @@ var LoginCliArgError = class extends Error {
|
|
|
1166
1422
|
};
|
|
1167
1423
|
function parseArgs(argv) {
|
|
1168
1424
|
const mkError = (m) => new LoginCliArgError(m);
|
|
1169
|
-
const reader = new
|
|
1425
|
+
const reader = new ArgReader(argv, KNOWN_FLAGS, mkError, VALUE_FLAGS);
|
|
1170
1426
|
const valueOf = (name) => reader.value(name);
|
|
1171
1427
|
const has = (name) => reader.has(name);
|
|
1172
1428
|
const help = has("--help") || has("-h");
|
|
1173
1429
|
const timeoutRaw = valueOf("--timeout");
|
|
1174
|
-
const timeoutMs = timeoutRaw === null ? 6e4 :
|
|
1175
|
-
if (!help && (!Number.isFinite(timeoutMs) || timeoutMs <= 0)) {
|
|
1176
|
-
throw new LoginCliArgError(`--timeout expects a positive integer (got ${timeoutRaw})`);
|
|
1177
|
-
}
|
|
1430
|
+
const timeoutMs = timeoutRaw === null || help ? 6e4 : parsePositiveInt("--timeout", timeoutRaw, mkError);
|
|
1178
1431
|
const args = {
|
|
1179
|
-
url:
|
|
1432
|
+
url: rejectEmptyValue("--url", valueOf("--url"), mkError) ?? "https://qontinui.io/login",
|
|
1180
1433
|
email: valueOf("--email") ?? process.env.UIB_LOGIN_EMAIL ?? "",
|
|
1181
1434
|
password: valueOf("--password") ?? process.env.UIB_LOGIN_PASSWORD ?? "",
|
|
1182
1435
|
// An EMPTY --success would make `landingPath.includes('')` true on any
|
|
1183
1436
|
// landing — ok:true while parked on the login page. Reject it.
|
|
1184
|
-
success:
|
|
1437
|
+
success: rejectEmptyValue("--success", valueOf("--success"), mkError) ?? "/dashboard",
|
|
1185
1438
|
timeoutMs,
|
|
1186
1439
|
headed: has("--headed"),
|
|
1187
1440
|
postClick: valueOf("--post-login-click"),
|
|
@@ -1196,21 +1449,19 @@ function parseArgs(argv) {
|
|
|
1196
1449
|
validateArgs(args);
|
|
1197
1450
|
return args;
|
|
1198
1451
|
}
|
|
1199
|
-
var
|
|
1452
|
+
var VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
1200
1453
|
"--url",
|
|
1201
1454
|
"--email",
|
|
1202
1455
|
"--password",
|
|
1203
1456
|
"--success",
|
|
1204
1457
|
"--timeout",
|
|
1205
|
-
"--headed",
|
|
1206
1458
|
"--post-login-click",
|
|
1207
1459
|
"--expect-text",
|
|
1208
1460
|
"--scroll-to",
|
|
1209
1461
|
"--screenshot",
|
|
1210
|
-
"--storage-state-out"
|
|
1211
|
-
"--keep-open",
|
|
1212
|
-
...cli_args_exports.COMMON_FLAGS
|
|
1462
|
+
"--storage-state-out"
|
|
1213
1463
|
]);
|
|
1464
|
+
var KNOWN_FLAGS = /* @__PURE__ */ new Set([...VALUE_FLAGS, "--headed", "--keep-open", ...COMMON_FLAGS]);
|
|
1214
1465
|
function validateArgs(args) {
|
|
1215
1466
|
if (args.help) return;
|
|
1216
1467
|
if (!/^https?:\/\//i.test(args.url)) {
|
|
@@ -1252,7 +1503,7 @@ ${USAGE}`);
|
|
|
1252
1503
|
screenshotPath,
|
|
1253
1504
|
storageStateOut
|
|
1254
1505
|
} = args;
|
|
1255
|
-
const log =
|
|
1506
|
+
const log = makeLogger("[login-web]", args.quiet);
|
|
1256
1507
|
const transport = createTransport({
|
|
1257
1508
|
kind: "injected",
|
|
1258
1509
|
options: { targetUrl: url, waitForSettle: false, readyTimeoutMs: 45e3, headed }
|
|
@@ -1284,9 +1535,9 @@ ${USAGE}`);
|
|
|
1284
1535
|
const onAppLoginPage = isAppLoginPath(finalUrl);
|
|
1285
1536
|
const stillOnCognito = isCognito(finalUrl);
|
|
1286
1537
|
const ok = !onAppLoginPage && !stillOnCognito && landingPath.includes(success);
|
|
1287
|
-
let
|
|
1288
|
-
if (!ok && !
|
|
1289
|
-
|
|
1538
|
+
let errorText2 = r.errorText;
|
|
1539
|
+
if (!ok && !errorText2) {
|
|
1540
|
+
errorText2 = await scrapeErrorCard(page);
|
|
1290
1541
|
}
|
|
1291
1542
|
let postLoginClicked = null;
|
|
1292
1543
|
if (ok && postClick) {
|
|
@@ -1376,7 +1627,7 @@ ${USAGE}`);
|
|
|
1376
1627
|
landingPath,
|
|
1377
1628
|
onAppLoginPage,
|
|
1378
1629
|
stillOnCognito,
|
|
1379
|
-
errorText,
|
|
1630
|
+
errorText: errorText2,
|
|
1380
1631
|
uiBridgeRoute,
|
|
1381
1632
|
uiBridgeRegistered: snap?.registration?.totalRegistered ?? null,
|
|
1382
1633
|
postLoginClicked,
|