trace-avatar-render 0.2.3 → 0.2.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.4
4
+
5
+ - `reroute` (in `direct()` and a campaign's `app`): addresses answered by others while filming, with the address bar unchanged, e.g. `{ "https://api.example.com": "https://demo-api.example.com" }` films a live front end against a demo API. Pages and API calls alike; redirects are followed inside (a redirect handed to the browser would reach the real address). Only what the browser fetches is rerouted. `rerouted(url, map)` is exported.
6
+
3
7
  ## 0.2.3
4
8
 
5
9
  - A director that fails leaves a screenshot of the page it was on: `failShot` in `direct()`; campaigns write `<out>/<render>.failed.png` (and remove a stale one when the render is made again).
@@ -2365,6 +2365,39 @@ async function routeAlias(context, alias) {
2365
2365
  await context.route(`${alias.url}/**`, forward(alias.local));
2366
2366
  if (alias.localApi) await context.route(`${alias.api}/**`, forward(alias.localApi));
2367
2367
  }
2368
+ function originOf(u, what) {
2369
+ let x;
2370
+ try {
2371
+ x = new URL(u);
2372
+ } catch {
2373
+ throw new Error(`reroute: ${what} ${u} isn't an address`);
2374
+ }
2375
+ if (!/^https?:$/.test(x.protocol) || x.pathname !== "/" && x.pathname !== "" || x.search || x.hash) throw new Error(`reroute: ${what} ${u} is an address without a path (https://host)`);
2376
+ return x.origin;
2377
+ }
2378
+ function rerouted(url, map) {
2379
+ let u;
2380
+ try {
2381
+ u = new URL(url);
2382
+ } catch {
2383
+ return null;
2384
+ }
2385
+ for (const [from, to] of Object.entries(map)) {
2386
+ if (u.origin === originOf(from, "from")) return `${originOf(to, "to")}${u.pathname}${u.search}`;
2387
+ }
2388
+ return null;
2389
+ }
2390
+ async function routeReroute(context, map) {
2391
+ for (const [from, to] of Object.entries(map)) {
2392
+ const origin = originOf(from, "from");
2393
+ originOf(to, "to");
2394
+ await context.route(`${origin}/**`, async (route) => {
2395
+ const target = rerouted(route.request().url(), map);
2396
+ const response = await route.fetch({ url: target });
2397
+ await route.fulfill({ response });
2398
+ });
2399
+ }
2400
+ }
2368
2401
  async function routeFolders(context, base2, routes) {
2369
2402
  for (const [prefix, dir] of Object.entries(routes)) {
2370
2403
  const root = resolve4(dir);
@@ -2431,6 +2464,7 @@ async function direct(o) {
2431
2464
  ...state ? { storageState: state } : {}
2432
2465
  });
2433
2466
  await routeAlias(context2, alias);
2467
+ if (o.reroute) await routeReroute(context2, o.reroute);
2434
2468
  if (o.routes) await routeFolders(context2, url, o.routes);
2435
2469
  const page2 = await context2.newPage();
2436
2470
  const cdp2 = await context2.newCDPSession(page2);
@@ -2950,6 +2984,7 @@ async function makeCampaign(c, o = {}) {
2950
2984
  ...v.signedIn === false ? { signedOut: true } : {},
2951
2985
  ...c.app.alias ? { alias: c.app.alias } : {},
2952
2986
  ...c.app.routes ? { routes: c.app.routes } : {},
2987
+ ...c.app.reroute ? { reroute: c.app.reroute } : {},
2953
2988
  // `d.app` in the script: the campaign's app, at the address the video shows (its alias, if it has one).
2954
2989
  props: { app: { ...c.app, url: c.app.alias ? `https://${typeof c.app.alias === "string" ? c.app.alias : c.app.alias.host}` : c.app.url } },
2955
2990
  ...speak ? { voice, ...script ? { voiceScript: script } : {} } : {},
@@ -3591,6 +3626,7 @@ export {
3591
3626
  cardCaption,
3592
3627
  cardsOf,
3593
3628
  aliasOf,
3629
+ rerouted,
3594
3630
  direct,
3595
3631
  USAGE,
3596
3632
  parse,
@@ -3612,4 +3648,4 @@ export {
3612
3648
  makeCampaign,
3613
3649
  saysOf
3614
3650
  };
3615
- //# sourceMappingURL=chunk-I4LM2D2B.js.map
3651
+ //# sourceMappingURL=chunk-7N5RZAMS.js.map