@qontinui/ui-bridge-wrapper 0.4.1 → 0.5.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 CHANGED
@@ -68,12 +68,20 @@ or a global/dev install:
68
68
 
69
69
  Each bin supports `--help`.
70
70
 
71
+ > **Version floor:** the bins exist only at `@qontinui/ui-bridge-wrapper` **>= 0.4.0**
72
+ > (the `scripts/` predecessors were deleted in the same release). A pin or cached
73
+ > npx resolution below that yields `command not found: ui-bridge-login-web` —
74
+ > upgrade rather than hunting for the bin. Also note: since 0.4.1 an explicit but
75
+ > EMPTY `--pages` errors (exit 2) instead of silently capturing the default page
76
+ > set, and (0.4.2) an empty `--success`/`--url` value is rejected rather than
77
+ > matching every landing page.
78
+
71
79
  ### Prerequisites for the browser-driving bins
72
80
 
73
- `ui-bridge-login-web` and `ui-bridge-capture-specs` launch Chromium via the
74
- injected transport, which dynamically imports `@qontinui/ui-bridge-headless`
75
- (it carries `playwright` as a real dependency). When installing the wrapper
76
- standalone you must therefore also:
81
+ `ui-bridge-inject`, `ui-bridge-login-web`, and `ui-bridge-capture-specs` all
82
+ launch Chromium via the injected transport, which dynamically imports
83
+ `@qontinui/ui-bridge-headless` (it carries `playwright` as a real dependency).
84
+ When installing the wrapper standalone you must therefore also:
77
85
 
78
86
  1. Install the optional `@qontinui/ui-bridge-headless` peer alongside it, and
79
87
  2. Run `npx playwright install chromium` once (or point `PLAYWRIGHT_BROWSERS_PATH`
@@ -230,36 +230,63 @@ var HeadlessTransport = class extends BaseTransport {
230
230
  uiBridgeBase: typeof raw["uiBridgeBase"] === "string" ? raw["uiBridgeBase"] : void 0,
231
231
  waitForUiBridgeMs: typeof raw["waitForUiBridgeMs"] === "number" ? raw["waitForUiBridgeMs"] : void 0,
232
232
  userAgent: typeof raw["userAgent"] === "string" ? raw["userAgent"] : void 0,
233
- forwardConsole: typeof raw["forwardConsole"] === "boolean" ? raw["forwardConsole"] : void 0
233
+ forwardConsole: typeof raw["forwardConsole"] === "boolean" ? raw["forwardConsole"] : void 0,
234
+ launchArgs: Array.isArray(raw["launchArgs"]) && raw["launchArgs"].every((a) => typeof a === "string") ? raw["launchArgs"] : void 0,
235
+ storageStatePath: typeof raw["storageStatePath"] === "string" ? raw["storageStatePath"] : void 0
234
236
  };
235
237
  }
236
238
  async onReady() {
237
239
  let launchHeadlessTab;
240
+ const headlessSpecifier = "@qontinui/ui-bridge-headless";
238
241
  try {
239
- ({ launchHeadlessTab } = await import('@qontinui/ui-bridge-headless'));
242
+ const mod = await import(headlessSpecifier);
243
+ ({ launchHeadlessTab } = mod);
240
244
  } catch (err) {
241
245
  const cause = err instanceof Error ? err.message : String(err);
242
- throw new WrapperTransportError(
243
- "INVALID_CONFIG",
244
- `Transport kind '${this.kind}' needs the optional '@qontinui/ui-bridge-headless' peer, which is not installed. Install it and the Chromium browser:
246
+ const code = err?.code;
247
+ if (code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND") {
248
+ throw new WrapperTransportError(
249
+ "INVALID_CONFIG",
250
+ `Transport kind '${this.kind}' needs the optional '@qontinui/ui-bridge-headless' peer, which is not installed. Install it and the Chromium browser:
245
251
  npm i @qontinui/ui-bridge-headless && npx playwright install chromium
246
252
  (bare \`npx @qontinui/ui-bridge-wrapper \u2026\` does NOT install peers \u2014 pass each peer with \`-p\`, e.g.
247
253
  npx -y -p @qontinui/ui-bridge-wrapper -p @qontinui/ui-bridge -p @qontinui/ui-bridge-headless -p playwright ui-bridge-login-web \u2026)
248
254
  Underlying import error: ${cause}`
255
+ );
256
+ }
257
+ throw new WrapperTransportError(
258
+ "INVALID_CONFIG",
259
+ `'@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}`
249
260
  );
250
261
  }
251
262
  const initScripts = await this.buildInitScripts();
252
- const tab = await launchHeadlessTab({
253
- url: this.options.targetUrl,
254
- headless: this.headless,
255
- uiBridgeBase: this.options.uiBridgeBase,
256
- waitForUiBridgeMs: this.options.waitForUiBridgeMs,
257
- viewportWidth: this.options.viewportWidth,
258
- viewportHeight: this.options.viewportHeight,
259
- userAgent: this.options.userAgent,
260
- forwardConsole: this.options.forwardConsole,
261
- initScripts: initScripts.length > 0 ? initScripts : void 0
262
- });
263
+ let tab;
264
+ try {
265
+ tab = await launchHeadlessTab({
266
+ url: this.options.targetUrl,
267
+ headless: this.headless,
268
+ uiBridgeBase: this.options.uiBridgeBase,
269
+ waitForUiBridgeMs: this.options.waitForUiBridgeMs,
270
+ viewportWidth: this.options.viewportWidth,
271
+ viewportHeight: this.options.viewportHeight,
272
+ userAgent: this.options.userAgent,
273
+ forwardConsole: this.options.forwardConsole,
274
+ initScripts: initScripts.length > 0 ? initScripts : void 0,
275
+ launchArgs: this.options.launchArgs && this.options.launchArgs.length > 0 ? this.options.launchArgs : void 0,
276
+ storageStatePath: this.options.storageStatePath
277
+ });
278
+ } catch (err) {
279
+ const cause = err instanceof Error ? err.message : String(err);
280
+ if (/Executable doesn't exist|browserType\.launch/i.test(cause)) {
281
+ throw new WrapperTransportError(
282
+ "INVALID_CONFIG",
283
+ `Playwright's Chromium browser is not installed (the '@qontinui/ui-bridge-headless' peer itself loaded fine). Run:
284
+ npx playwright install chromium
285
+ Underlying launch error: ${cause}`
286
+ );
287
+ }
288
+ throw err;
289
+ }
263
290
  this.tab = {
264
291
  browser: tab.browser,
265
292
  context: tab.context,
@@ -710,6 +737,13 @@ var COMMON_FLAGS = /* @__PURE__ */ new Set(["--help", "-h", "--quiet"]);
710
737
  function isFlagShaped(value) {
711
738
  return value.startsWith("--");
712
739
  }
740
+ function consumeValue(flag, raw, error) {
741
+ if (raw === void 0) return null;
742
+ if (isFlagShaped(raw)) {
743
+ throw error(`${flag} expects a value but got the flag '${raw}' \u2014 did you omit ${flag}'s argument?`);
744
+ }
745
+ return raw;
746
+ }
713
747
  var ArgReader = class {
714
748
  argv;
715
749
  error;
@@ -734,18 +768,14 @@ var ArgReader = class {
734
768
  /**
735
769
  * Value following the value-flag `name`, or `null` when the flag is absent OR
736
770
  * has no following token (the caller defaults it). Throws when the following
737
- * token is flag-shaped — the swallow this kit exists to kill.
771
+ * token is flag-shaped — the swallow this kit exists to kill. Delegates to
772
+ * {@link consumeValue} so the guard (and its message) live in exactly one
773
+ * place for both the indexOf-style and switch-style parsers.
738
774
  */
739
775
  value(name) {
740
776
  const i = this.argv.indexOf(name);
741
777
  if (i < 0 || i + 1 >= this.argv.length) return null;
742
- const raw = this.argv[i + 1];
743
- if (isFlagShaped(raw)) {
744
- throw this.error(
745
- `${name} expects a value but got the flag '${raw}' \u2014 did you omit ${name}'s argument?`
746
- );
747
- }
748
- return raw;
778
+ return consumeValue(name, this.argv[i + 1], this.error);
749
779
  }
750
780
  };
751
781
  function makeLogger(prefix, quiet) {
@@ -862,7 +892,7 @@ async function loginDrive(page, { email, password, timeoutMs, log = () => {
862
892
  } catch {
863
893
  const errorText2 = await scrapeErrorCard(page);
864
894
  const finalUrl2 = page.url();
865
- log(`final ${finalUrl2} (stalled)`);
895
+ log(`stalled ${finalUrl2}`);
866
896
  return { ok: false, finalUrl: finalUrl2, landingPath: pathOf(finalUrl2), errorText: errorText2 };
867
897
  }
868
898
  }
@@ -874,9 +904,9 @@ async function loginDrive(page, { email, password, timeoutMs, log = () => {
874
904
  ).catch(() => {
875
905
  });
876
906
  const finalUrl = page.url();
877
- log(`final ${finalUrl}`);
878
907
  const landingPath = await page.evaluate(() => location.pathname).catch(() => pathOf(finalUrl));
879
908
  const ok = !isAppLoginPath(finalUrl) && !isCognito(finalUrl) && !/\/auth\/callback/.test(pathOf(finalUrl));
909
+ log(ok ? `authed ${finalUrl}` : `stalled ${finalUrl}`);
880
910
  const errorText = ok ? null : await scrapeErrorCard(page);
881
911
  return { ok, finalUrl, landingPath, errorText };
882
912
  }