@betterportal/framework 10.6.35 → 10.7.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.
Files changed (41) hide show
  1. package/lib/adapters/h3.d.ts +2 -0
  2. package/lib/adapters/h3.d.ts.map +1 -1
  3. package/lib/adapters/h3.js +237 -134
  4. package/lib/adapters/h3.js.map +1 -1
  5. package/lib/cli/bp.js +14 -0
  6. package/lib/cli/bp.js.map +1 -1
  7. package/lib/codegen/cli.js +7 -0
  8. package/lib/codegen/cli.js.map +1 -1
  9. package/lib/codegen/init.js +5 -0
  10. package/lib/codegen/init.js.map +1 -1
  11. package/lib/codegen/routeUrlPolicy.d.ts +15 -0
  12. package/lib/codegen/routeUrlPolicy.d.ts.map +1 -0
  13. package/lib/codegen/routeUrlPolicy.js +1012 -0
  14. package/lib/codegen/routeUrlPolicy.js.map +1 -0
  15. package/lib/contracts/registry.d.ts +9 -12
  16. package/lib/contracts/registry.d.ts.map +1 -1
  17. package/lib/contracts/route.d.ts +6 -27
  18. package/lib/contracts/route.d.ts.map +1 -1
  19. package/lib/contracts/route.js.map +1 -1
  20. package/lib/contracts/routeUrl.d.ts +66 -0
  21. package/lib/contracts/routeUrl.d.ts.map +1 -0
  22. package/lib/contracts/routeUrl.js +2 -0
  23. package/lib/contracts/routeUrl.js.map +1 -0
  24. package/lib/contracts/streaming.d.ts +6 -4
  25. package/lib/contracts/streaming.d.ts.map +1 -1
  26. package/lib/contracts/streaming.js.map +1 -1
  27. package/lib/index.d.ts +1 -0
  28. package/lib/index.d.ts.map +1 -1
  29. package/lib/index.js +1 -0
  30. package/lib/index.js.map +1 -1
  31. package/lib/runtime/auth/redirect.d.ts +13 -2
  32. package/lib/runtime/auth/redirect.d.ts.map +1 -1
  33. package/lib/runtime/auth/redirect.js +1 -1
  34. package/lib/runtime/auth/redirect.js.map +1 -1
  35. package/lib/runtime/configProvider.d.ts +8 -0
  36. package/lib/runtime/configProvider.d.ts.map +1 -1
  37. package/lib/runtime/configProvider.js +16 -0
  38. package/lib/runtime/configProvider.js.map +1 -1
  39. package/lib/runtime/llms.js +6 -6
  40. package/lib/runtime/llms.js.map +1 -1
  41. package/package.json +1 -1
@@ -13,6 +13,8 @@ export interface H3RouterObservabilityOptions {
13
13
  createRequestObservability?: (name: string, attributes: ObservabilityAttributes) => BetterPortalObservability;
14
14
  /** Identifier of the service hosting this router (used by ctx.serviceId). */
15
15
  serviceId?: string;
16
+ /** Current installed instance used for URL resolution; evaluated after configuration/installation changes. */
17
+ resolveRouteUrlServiceId?: () => string | undefined;
16
18
  /** Resolve auth context for a request. Returning undefined disables auth enforcement for the request. */
17
19
  resolveAuth?: (event: BetterPortalEvent, route: RegisteredRoute) => Promise<H3AuthContext | undefined> | H3AuthContext | undefined;
18
20
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"h3.d.ts","sourceRoot":"","sources":["../../src/adapters/h3.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAuB,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,KAAK,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxG,OAAO,KAAK,EAAsB,oBAAoB,EAAE,eAAe,EAAwD,MAAM,0BAA0B,CAAC;AAChK,OAAO,KAAK,EAGV,WAAW,EAIX,mBAAmB,EAEnB,oBAAoB,EAIrB,MAAM,uBAAuB,CAAC;AAI/B,OAAO,KAAK,EAAE,aAAa,EAAa,MAAM,sBAAsB,CAAC;AAErE,OAAO,EASL,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACvB,MAAM,kBAAkB,CAAC;AA0B1B,KAAK,0BAA0B,GAAG,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAA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,CAAC;IAChD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,aAAa,CAAC,EAAE,aAAa,CAAC;IACvC;;;;OAIG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC7D,QAAQ,CAAC,YAAY,CAAC,EAAE;QACtB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;KACzB,CAAC;CACH;AAgLD,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAKvE;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,aAAa,CAAC,eAAe,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAExG;AAuHD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,oBAAoB,EAC9B,GAAG,EAAE,iBAAiB,EACtB,OAAO,GAAE,4BAAiC,GACzC,IAAI,CA6GN;AAmkDD;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,iBAAiB,EACtB,QAAQ,EAAE,cAAc,EACxB,QAAQ,EAAE,cAAc,EACxB,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAC;IAC5F,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,gBAAgB,GAAG,IAAI,CAAC;CAChE,GACL,IAAI,CAoEN"}
@@ -1,3 +1,4 @@
1
+ import { routeMountServicePath, safeServiceBaseUrl } from "../runtime/configProvider.js";
1
2
  import { ElevationRequired, requireElevation, elevationResponse } from "../runtime/auth/elevation.js";
2
3
  import { createEventStream, getRequestIP, getRequestURL } from "h3";
3
4
  import { renderThemeLlmsDrop } from "../runtime/llms.js";
@@ -245,8 +246,7 @@ async function prepareSseContext(registryRoutes, dependencyAliases, route, event
245
246
  callerMode: authResult.callerMode,
246
247
  ...extraContext,
247
248
  serviceId: routerOptions.serviceId,
248
- routeUrl: createServiceRouteUrlBuilder(registryRoutes, extraContext, dependencyAliases, routerOptions.serviceId),
249
- uiRouteUrl: createUiRouteUrlBuilder(event, extraContext, dependencyAliases, routerOptions.serviceId),
249
+ routeUrl: createRouteUrlBuilder(event, registryRoutes, extraContext, dependencyAliases, routerOptions.resolveRouteUrlServiceId?.() ?? routerOptions.serviceId, { path: url.pathname.replace(/\/__sse\/?$/, ""), template: route.path, method: "GET", params, query: queryResult.value }),
250
250
  diagnostic: (diagnostic) => annotateHttpOutcome(event, diagnostic),
251
251
  response: responseHelper,
252
252
  file: fileResponseHelper,
@@ -299,7 +299,6 @@ export function createH3Router(registry, app, options = {}) {
299
299
  callerMode: context.callerMode,
300
300
  serviceId: context.serviceId,
301
301
  routeUrl: context.routeUrl,
302
- uiRouteUrl: context.uiRouteUrl,
303
302
  config: context.config,
304
303
  ...(context.plugin ? { plugin: context.plugin } : {}),
305
304
  signal: abort.signal,
@@ -409,12 +408,16 @@ function routePathsMatch(left, right) {
409
408
  return false;
410
409
  return a.every((segment, index) => {
411
410
  const other = b[index];
412
- return segment === other || pathParamName(segment) !== null || pathParamName(other) !== null;
411
+ if (pathParamName(segment) !== null || pathParamName(other) !== null)
412
+ return true;
413
+ try {
414
+ return decodeURIComponent(segment) === decodeURIComponent(other);
415
+ }
416
+ catch {
417
+ return false;
418
+ }
413
419
  });
414
420
  }
415
- function routeMountServicePath(routeMount) {
416
- return routeMount.resolvedServicePath ?? routeMount.servicePathVariant ?? routeMount.targetPath;
417
- }
418
421
  function appAllowsRoute(app, route, method, url, acceptHeader) {
419
422
  // Well-known routes are control-plane/service endpoints. Their access policy
420
423
  // is declared by the route and must not depend on being mounted as an app page.
@@ -473,25 +476,29 @@ function fillAppPath(path, params = {}) {
473
476
  return null;
474
477
  return queryPart ? `${resolved}?${queryPart}` : resolved;
475
478
  }
476
- function selectRegisteredRoute(routes, viewId, params = {}) {
477
- const matches = routes
478
- .filter((candidate) => candidate.viewId === viewId)
479
- .filter((candidate) => candidate.paramNames.every((name) => params[name] !== null && params[name] !== undefined))
480
- .sort((a, b) => b.paramNames.length - a.paramNames.length);
481
- return matches[0] ?? null;
482
- }
483
479
  function appOrigin(app, override) {
484
- const raw = (override ?? app.hostnames[0] ?? "").replace(/\/+$/, "");
485
- if (raw.startsWith("http://") || raw.startsWith("https://"))
486
- return raw;
487
- return `https://${raw}`;
480
+ for (const value of override ? [override] : app.hostnames) {
481
+ try {
482
+ const raw = value.trim();
483
+ if (!raw)
484
+ continue;
485
+ const parsed = new URL(/^https?:\/\//i.test(raw) ? raw : `https://${raw}`);
486
+ if (!["http:", "https:"].includes(parsed.protocol) || parsed.username || parsed.password || parsed.search || parsed.hash || parsed.pathname !== "/")
487
+ continue;
488
+ return parsed.origin;
489
+ }
490
+ catch { /* Ignore unsafe configured app hosts. */ }
491
+ }
492
+ return null;
488
493
  }
489
494
  function requestAppOrigin(app, event) {
490
495
  const headers = event.req.headers;
491
496
  for (const candidate of buildHostCandidates(headers, "theme")) {
492
- const hostname = app.hostnames.find((entry) => hostFromHeaderValue(entry) === candidate.host);
493
- if (hostname)
494
- return appOrigin(app, hostname);
497
+ for (const hostname of app.hostnames.filter(entry => hostFromHeaderValue(entry) === candidate.host)) {
498
+ const origin = appOrigin(app, hostname);
499
+ if (origin)
500
+ return origin;
501
+ }
495
502
  }
496
503
  return undefined;
497
504
  }
@@ -499,39 +506,52 @@ function serviceOrigin(extraContext, serviceId, override) {
499
506
  if (override)
500
507
  return appOrigin(extraContext.app, override);
501
508
  const service = extraContext.tenant.services.find((candidate) => candidate.enabled && (candidate.id === serviceId || candidate.serviceId === serviceId));
502
- return service ? service.hostname.replace(/\/+$/, "") : null;
509
+ return service ? safeServiceBaseUrl(service) ?? null : null;
503
510
  }
504
511
  function appendQuery(path, query = {}, absoluteOrigin, sse = false) {
505
- const url = new URL(path, absoluteOrigin ?? "http://betterportal.invalid");
512
+ const url = new URL(absoluteOrigin ? absoluteOrigin.replace(/\/+$/, "") + path : path, "http://betterportal.invalid");
506
513
  if (sse)
507
514
  url.pathname = `${url.pathname.replace(/\/+$/, "")}/__sse`;
508
515
  for (const [key, value] of Object.entries(query)) {
509
- if (value !== null && value !== undefined)
516
+ if (Array.isArray(value)) {
517
+ const pairs = [...url.searchParams];
518
+ const index = pairs.findIndex(([name]) => name === key);
519
+ const retained = pairs.filter(([name]) => name !== key);
520
+ retained.splice(index < 0 ? retained.length : index, 0, ...value.filter(item => item !== null && item !== undefined).map(item => [key, String(item)]));
521
+ url.search = "";
522
+ for (const [name, item] of retained)
523
+ url.searchParams.append(name, item);
524
+ }
525
+ else if (value !== null && value !== undefined)
510
526
  url.searchParams.set(key, String(value));
527
+ else
528
+ url.searchParams.delete(key);
511
529
  }
512
530
  return absoluteOrigin ? url.toString() : `${url.pathname}${url.search}${url.hash}`;
513
531
  }
514
- function renderUrl(path, options = {}) {
515
- const query = { ...(options.query ?? {}) };
532
+ function renderUrl(path, options = {}, origin) {
533
+ const query = { ...(options.query ?? {}), _c: null, _f: null };
516
534
  if (options.component)
517
535
  query._c = options.component;
518
536
  if (options.fragment)
519
537
  query._f = options.fragment;
520
- return appendQuery(path, query, options.absolute ? options.origin : undefined, options.sse);
538
+ return appendQuery(path, query, origin, options.sse);
521
539
  }
522
- function createRouteUiAttributes(url, options = {}, form = false) {
523
- const method = (options.method ?? "GET").toLowerCase();
524
- const methodAttr = `hx-${method}`;
540
+ function createRouteUiAttributes(route, options = {}, form = false) {
541
+ const method = options.method ?? "GET";
542
+ const request = route.absoluteViewPath ?? route.viewPath;
525
543
  const attrs = form
526
- ? { action: url, method: (options.method ?? "GET") }
527
- : { href: url };
528
- attrs[methodAttr] = url;
544
+ ? { action: request, method }
545
+ : { href: route.uiPath ?? request };
546
+ attrs[`hx-${method.toLowerCase()}`] = request;
529
547
  if (options.target)
530
548
  attrs["hx-target"] = options.target;
531
549
  if (options.swap)
532
550
  attrs["hx-swap"] = options.swap;
533
551
  if (options.push !== undefined)
534
552
  attrs["hx-push-url"] = String(options.push);
553
+ else if (method === "GET" && route.uiPath && !options.target)
554
+ attrs["hx-push-url"] = route.uiPath;
535
555
  return attrs;
536
556
  }
537
557
  function createElementResolver(extraContext, dependencyAliases) {
@@ -573,17 +593,14 @@ function createElementResolver(extraContext, dependencyAliases) {
573
593
  return { unavailable: "path_params_required" };
574
594
  return {
575
595
  serviceId: mount.serviceId,
576
- url: renderUrl(servicePath, { absolute: true, origin, query: reference.args?.query, fragment: reference.fragment })
596
+ url: renderUrl(servicePath, { query: reference.args?.query, fragment: reference.fragment }, origin)
577
597
  };
578
598
  };
579
599
  }
580
600
  function createViewRenderContext(route, ctx, dependencyAliases, renderer, mode, kind, key, status) {
581
- const current = (options = {}) => renderUrl(ctx.path, options);
582
- const path = (value, options = {}) => renderUrl(value, options);
583
- const routeUrl = (viewId, options) => ctx.routeUrl?.(viewId, options) ?? null;
584
- const uiRoute = (viewId, options) => ctx.uiRouteUrl?.(viewId, options) ?? null;
585
- const ui = (url, options) => createRouteUiAttributes(url, options);
586
- const form = (url, options) => createRouteUiAttributes(url, options, true);
601
+ const routeUrl = (input) => ctx.routeUrl?.(input) ?? null;
602
+ const ui = (resolved, options) => createRouteUiAttributes(resolved, options);
603
+ const form = (resolved, options) => createRouteUiAttributes(resolved, options, true);
587
604
  return {
588
605
  tenant: {
589
606
  id: ctx.tenant.id,
@@ -602,16 +619,22 @@ function createViewRenderContext(route, ctx, dependencyAliases, renderer, mode,
602
619
  auth: {
603
620
  serviceId: ctx.app.auth.serviceId,
604
621
  ...(ctx.app.auth.loginViewId ? { loginViewId: ctx.app.auth.loginViewId } : {}),
605
- ...(ctx.app.auth.logoutViewId ? { logoutViewId: ctx.app.auth.logoutViewId } : {})
622
+ ...(ctx.app.auth.logoutViewId ? { logoutViewId: ctx.app.auth.logoutViewId } : {}),
623
+ ...(ctx.app.auth.redirects ? { redirects: structuredClone(ctx.app.auth.redirects) } : {})
606
624
  }
607
625
  } : {})
608
626
  },
609
627
  request: { method: ctx.method, path: ctx.path, params: ctx.params, query: ctx.query },
610
628
  route: { viewId: route.viewId, path: route.path, renderer, mode, kind, key, status },
611
- url: { current, path, route: routeUrl, uiRoute },
629
+ routeUrl,
612
630
  routeUi: {
613
631
  link: ui,
614
- current: (options = {}) => ui(current(options), options),
632
+ current: (options = {}) => {
633
+ const resolved = routeUrl({ ...options, method: options.method ?? "GET" });
634
+ if (!resolved)
635
+ throw new Error("Current route URL could not be resolved");
636
+ return ui(resolved, options);
637
+ },
615
638
  fragment: ui,
616
639
  form
617
640
  },
@@ -633,89 +656,171 @@ function serviceReferenceIds(extraContext, reference, dependencyAliases) {
633
656
  }
634
657
  return ids;
635
658
  }
636
- function createServiceRouteUrlBuilder(routes, extraContext, dependencyAliases, currentServiceId) {
637
- return (viewId, options = {}) => {
638
- const targetServiceId = options.serviceId ?? currentServiceId;
639
- if (!targetServiceId)
659
+ /** Resolve every destination from one method-aware service/mount lookup. */
660
+ function createRouteUrlBuilder(event, routes, extraContext, aliases, currentServiceId, current) {
661
+ return (input = {}) => {
662
+ // Also reject legacy options from untyped callers, rather than silently guessing.
663
+ if (typeof input !== "object" || input === null || "absolute" in input || "origin" in input)
640
664
  return null;
641
- const targetIds = serviceReferenceIds(extraContext, targetServiceId, dependencyAliases);
642
- const currentIds = currentServiceId
643
- ? serviceReferenceIds(extraContext, currentServiceId, dependencyAliases)
644
- : new Set();
645
- const isCurrentService = [...targetIds].some((id) => currentIds.has(id));
646
- if (isCurrentService) {
647
- const route = selectRegisteredRoute(routes, viewId, options.params);
648
- if (!route)
649
- return null;
650
- const origin = options.absolute ? serviceOrigin(extraContext, targetServiceId, options.origin) : undefined;
651
- if (options.absolute && !origin)
652
- return null;
653
- const path = fillAppPath(route.path, options.params);
654
- return path ? renderUrl(path, { ...options, origin: origin ?? undefined }) : null;
655
- }
656
- const mounts = appRouteIndex(extraContext.app).filter((candidate) => candidate.enabled !== false
657
- && candidate.viewId === viewId
658
- && targetIds.has(candidate.serviceId)
659
- && Boolean(routeMountServicePath(candidate)));
660
- const targets = new Map(mounts.map((mount) => [`${mount.serviceId}\0${routeMountServicePath(mount)}`, mount]));
661
- if (targets.size !== 1)
665
+ if (input.path !== undefined && input.viewId !== undefined)
662
666
  return null;
663
- const mount = [...targets.values()][0];
664
- const servicePath = routeMountServicePath(mount);
665
- const origin = options.absolute ? serviceOrigin(extraContext, mount.serviceId, options.origin) : undefined;
666
- if (options.absolute && !origin)
667
+ const self = input.path === undefined && input.viewId === undefined;
668
+ const currentRoute = routes.find(route => route.methods.includes(current.method) && route.path === current.template);
669
+ const inferred = new Set(appRouteIndex(extraContext.app).filter(mount => mount.enabled !== false && mount.viewId === currentRoute?.viewId).map(mount => mount.serviceId));
670
+ const owner = currentServiceId ?? extraContext.serviceId ?? (inferred.size === 1 ? [...inferred][0] : undefined);
671
+ const reference = input.serviceId ?? owner;
672
+ if (!reference)
667
673
  return null;
668
- const path = fillAppPath(servicePath, { ...mount.fixedParams, ...(options.params ?? {}) });
669
- return path ? renderUrl(path, { ...options, origin: origin ?? undefined }) : null;
670
- };
671
- }
672
- const BP_ROUTE_TOKEN_ATTRS = ["href", "action", "hx-get", "hx-post", "hx-put", "hx-patch", "hx-delete", "hx-download"];
673
- function rewriteServiceRouteTokens(html, routeUrl, obs) {
674
- let rewritten = html;
675
- for (const attr of BP_ROUTE_TOKEN_ATTRS) {
676
- const attrRe = new RegExp(`(?<![\\w:-])${attr}=(["'])\\{([A-Za-z0-9_$.-]+)\\}([^"']*)\\1`, "g");
677
- rewritten = rewritten.replace(attrRe, (match, quote, viewId, suffix) => {
678
- if (suffix) {
679
- obs?.logger.warn("BP route token must occupy the whole attribute: attr={attr} viewId={viewId}; use the renderer URL helper for params/query", { attr, viewId });
680
- return match;
681
- }
682
- const resolved = routeUrl?.(viewId);
683
- if (!resolved) {
684
- obs?.logger.warn("BP route token unresolved: attr={attr} viewId={viewId}", { attr, viewId });
685
- return match;
674
+ const ids = serviceReferenceIds(extraContext, reference, aliases);
675
+ const ownerKey = owner ? aliases[owner] ?? owner : undefined;
676
+ const owners = extraContext.tenant.services.filter(service => service.enabled && (service.id === ownerKey || service.serviceId === ownerKey));
677
+ const currentInstance = owners.length === 1 ? owners[0].id : owners.length === 0 ? owner : undefined;
678
+ const targetInstances = extraContext.tenant.services.filter(service => service.enabled && ids.has(service.id));
679
+ const ownService = currentInstance !== undefined && (targetInstances.length === 1
680
+ ? targetInstances[0].id === currentInstance
681
+ : targetInstances.length === 0 && reference === currentInstance);
682
+ if (self && !ownService)
683
+ return null;
684
+ if (!ownService && !extraContext.tenant.services.some(service => service.enabled && ids.has(service.id)))
685
+ return null;
686
+ const method = input.method ?? (self ? current.method : "GET");
687
+ if (input.sse && (method !== "GET" || !ownService))
688
+ return null;
689
+ const params = { ...(self ? current.params : {}), ...input.params };
690
+ const embeddedQuery = {};
691
+ const queryOffset = input.path?.indexOf("?") ?? -1;
692
+ const embeddedPairs = new URLSearchParams(queryOffset >= 0 ? input.path.slice(queryOffset + 1) : "");
693
+ for (const key of new Set(embeddedPairs.keys())) {
694
+ const values = embeddedPairs.getAll(key);
695
+ embeddedQuery[key] = values.length === 1 ? values[0] : values;
696
+ }
697
+ const inheritedQuery = { ...current.query };
698
+ if (self) {
699
+ const requestPairs = getRequestURL(event).searchParams;
700
+ for (const key of new Set(requestPairs.keys())) {
701
+ const values = requestPairs.getAll(key);
702
+ if (values.length > 1 && Object.prototype.hasOwnProperty.call(inheritedQuery, key))
703
+ inheritedQuery[key] = values;
686
704
  }
687
- return `${attr}=${quote}${resolved}${quote}`;
688
- });
689
- }
690
- return rewritten;
691
- }
692
- function createUiRouteUrlBuilder(event, extraContext, dependencyAliases, currentServiceId) {
693
- return (viewId, options = {}) => {
694
- const targetServiceId = options.serviceId ?? currentServiceId;
695
- if (!targetServiceId)
705
+ }
706
+ const query = { ...(self ? inheritedQuery : {}), ...embeddedQuery, ...input.query };
707
+ if (input.component && input.fragment)
696
708
  return null;
697
- const serviceIds = serviceReferenceIds(extraContext, targetServiceId, dependencyAliases);
698
- const routes = appRouteIndex(extraContext.app).filter((candidate) => candidate.enabled !== false
699
- && (candidate.kind ?? "page") === "page"
700
- && (candidate.resolvedMethods?.includes("GET") ?? false)
701
- && candidate.viewId === viewId
702
- && serviceIds.has(candidate.serviceId));
703
- const resolved = routes.flatMap((route) => {
704
- const path = fillAppPath(route.path, options.params);
705
- return path ? [{ route, path }] : [];
706
- });
707
- const uniquePaths = new Map(resolved.map((entry) => [entry.path, entry]));
708
- if (uniquePaths.size !== 1)
709
+ const suppliedPath = self ? currentRoute?.path ?? current.path : input.path;
710
+ if (suppliedPath !== undefined && (!suppliedPath.startsWith("/") || suppliedPath.startsWith("//") || suppliedPath.includes("\\") || suppliedPath.includes("#") || [...suppliedPath].some(char => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127)))
709
711
  return null;
710
- const { path } = [...uniquePaths.values()][0];
711
- const origin = options.absolute
712
- ? options.origin
713
- ? appOrigin(extraContext.app, options.origin)
714
- : requestAppOrigin(extraContext.app, event) ?? appOrigin(extraContext.app)
715
- : undefined;
716
- return appendQuery(path, options.query, origin);
712
+ const pathname = suppliedPath?.split("?", 1)[0];
713
+ let serviceId = ownService ? currentInstance : reference;
714
+ let path = null;
715
+ let viewId = input.viewId;
716
+ if (ownService) {
717
+ let candidates = routes.filter(route => route.methods.includes(method) && (viewId !== undefined
718
+ ? route.viewId === viewId
719
+ : pathname !== undefined && routePathsMatch(route.path, pathname)));
720
+ // A supplied template identifies its declaration before wildcard matching.
721
+ const exact = pathname === undefined ? [] : candidates.filter(route => normalizeRoutePath(route.path) === normalizeRoutePath(pathname));
722
+ if (exact.length)
723
+ candidates = exact;
724
+ const resolved = candidates.flatMap(route => {
725
+ const mounts = appRouteIndex(extraContext.app).filter(mount => mount.enabled !== false && mount.serviceId === currentInstance
726
+ && mount.viewId === route.viewId && mount.resolvedMethods?.includes(method)
727
+ && (input.mountId === undefined || mount.id === input.mountId)
728
+ && (!routeMountServicePath(mount) || routePathsMatch(routeMountServicePath(mount), route.path)));
729
+ const defaults = mounts.length ? mounts.map(mount => mount.fixedParams ?? {}) : [{}];
730
+ return defaults.flatMap(fixed => {
731
+ const concrete = fillAppPath(suppliedPath ?? route.path, { ...fixed, ...params });
732
+ return concrete && !concrete.split("?", 1)[0].split("/").some(part => pathParamName(part)) ? [{ route, path: concrete }] : [];
733
+ });
734
+ });
735
+ // Concrete paths follow the router's earliest literal-segment precedence.
736
+ const rank = (path) => path.split("/").map(part => pathParamName(part) ? "1" : "0").join("");
737
+ const parameterCount = (path) => path.split("/").filter(part => pathParamName(part)).length;
738
+ const compare = (a, b) => input.viewId === undefined ? rank(a).localeCompare(rank(b)) : parameterCount(b) - parameterCount(a);
739
+ resolved.sort((a, b) => compare(a.route.path, b.route.path));
740
+ const best = resolved[0];
741
+ if (!best)
742
+ return null;
743
+ if (input.sse && !best.route.sse && !isStreamHandler(best.route.handlers.GET))
744
+ return null;
745
+ if (new Set(resolved.filter(entry => compare(entry.route.path, best.route.path) === 0).map(entry => entry.path)).size !== 1)
746
+ return null;
747
+ path = best.path;
748
+ viewId = best.route.viewId;
749
+ }
750
+ else {
751
+ let targets = appRouteIndex(extraContext.app).filter(mount => mount.enabled !== false && ids.has(mount.serviceId)
752
+ && (mount.resolvedMethods?.includes(method) ?? false)
753
+ && (input.mountId === undefined || mount.id === input.mountId)
754
+ && (viewId !== undefined ? mount.viewId === viewId : pathname !== undefined && Boolean(routeMountServicePath(mount)) && routePathsMatch(routeMountServicePath(mount), pathname)));
755
+ const exact = pathname === undefined ? [] : targets.filter(mount => normalizeRoutePath(routeMountServicePath(mount)) === normalizeRoutePath(pathname));
756
+ if (exact.length)
757
+ targets = exact;
758
+ if (pathname !== undefined && targets.length) {
759
+ const rank = (mount) => routeMountServicePath(mount).split("/").map(part => pathParamName(part) ? "1" : "0").join("");
760
+ const best = targets.map(rank).sort()[0];
761
+ targets = targets.filter(mount => rank(mount) === best);
762
+ }
763
+ const resolved = targets.flatMap(mount => {
764
+ const concrete = fillAppPath(suppliedPath ?? routeMountServicePath(mount) ?? "", { ...mount.fixedParams, ...params });
765
+ return concrete ? [{ mount, path: concrete }] : [];
766
+ });
767
+ const unique = new Map(resolved.map(entry => [`${entry.mount.serviceId}\0${entry.path}`, entry]));
768
+ if (unique.size !== 1)
769
+ return null;
770
+ const entry = [...unique.values()][0];
771
+ serviceId = entry.mount.serviceId;
772
+ path = entry.path;
773
+ viewId = entry.mount.viewId;
774
+ }
775
+ try {
776
+ if (path.split("?", 1)[0].split("/").some(part => [".", ".."].includes(decodeURIComponent(part))))
777
+ return null;
778
+ }
779
+ catch {
780
+ return null;
781
+ }
782
+ const serviceBase = serviceOrigin(extraContext, serviceId) ?? undefined;
783
+ const options = { ...input, params, query };
784
+ const apiPath = renderUrl(path, { query, sse: input.sse });
785
+ const viewPath = renderUrl(path, options);
786
+ const pageMounts = method === "GET" && !input.sse && !input.component && !input.fragment
787
+ ? appRouteIndex(extraContext.app).filter(mount => mount.enabled !== false && (mount.kind ?? "page") === "page"
788
+ && (mount.resolvedMethods?.includes("GET") ?? false) && mount.serviceId === serviceId && mount.viewId === viewId
789
+ && (input.mountId === undefined || input.mountId === mount.id))
790
+ : [];
791
+ const pagePaths = new Set(pageMounts.flatMap(mount => {
792
+ const values = { ...mount.fixedParams, ...params, ...routeParamsFromPath(routeMountServicePath(mount) ?? (ownService ? routes.find(route => route.viewId === viewId && routePathsMatch(route.path, path.split("?", 1)[0]))?.path : undefined) ?? "", path.split("?", 1)[0]) };
793
+ const uiNames = new Set(mount.path.split("/").flatMap(part => pathParamName(part) ? [pathParamName(part)] : []));
794
+ if (Object.entries(mount.fixedParams ?? {}).some(([name, value]) => !uiNames.has(name) && values[name] !== value))
795
+ return [];
796
+ const target = fillAppPath(mount.path, values);
797
+ const service = fillAppPath(routeMountServicePath(mount) ?? (ownService ? routes.find(route => route.viewId === viewId && routePathsMatch(route.path, path.split("?", 1)[0]))?.path : undefined) ?? "", values);
798
+ return target && service && routePathsMatch(service, path.split("?", 1)[0]) ? [renderUrl(target, { query })] : [];
799
+ }));
800
+ const uiPath = pagePaths.size === 1 ? [...pagePaths][0] : null;
801
+ const appBase = requestAppOrigin(extraContext.app, event) ?? (extraContext.app.hostnames.length ? appOrigin(extraContext.app) : undefined);
802
+ return {
803
+ apiPath, viewPath, uiPath,
804
+ absoluteApiPath: serviceBase ? renderUrl(path, { query, sse: input.sse }, serviceBase) : null,
805
+ absoluteViewPath: serviceBase ? renderUrl(path, options, serviceBase) : null,
806
+ absoluteUiPath: uiPath && appBase ? new URL(uiPath, appBase).toString() : null
807
+ };
717
808
  };
718
809
  }
810
+ function routeParamsFromPath(template, path) {
811
+ const parts = path.split("/");
812
+ return Object.fromEntries(template.split("/").flatMap((part, index) => {
813
+ const name = pathParamName(part);
814
+ if (!name || parts[index] === undefined)
815
+ return [];
816
+ try {
817
+ return [[name, decodeURIComponent(parts[index])]];
818
+ }
819
+ catch {
820
+ return [];
821
+ }
822
+ }));
823
+ }
719
824
  function rejectUnallowedAppRoute(obs, route, method, extraContext, reason) {
720
825
  obs?.logger.warn("BP route rejected by app allowlist: tenant={tenantId} app={appId} route={viewId} method={method} reason={reason}", {
721
826
  tenantId: extraContext.tenant.id,
@@ -871,8 +976,7 @@ async function handleRouteRequest(registryRoutes, dependencyAliases, route, meth
871
976
  if (!routeAllowance.allowed) {
872
977
  return rejectUnallowedAppRoute(obs, route, method, extraContext, routeAllowance.reason ?? "route_not_mounted_for_app");
873
978
  }
874
- const routeUrl = createServiceRouteUrlBuilder(registryRoutes, extraContext, dependencyAliases, routerOptions.serviceId);
875
- const uiRouteUrl = createUiRouteUrlBuilder(event, extraContext, dependencyAliases, routerOptions.serviceId);
979
+ const routeUrl = createRouteUrlBuilder(event, registryRoutes, extraContext, dependencyAliases, routerOptions.resolveRouteUrlServiceId?.() ?? routerOptions.serviceId, { path: url.pathname, template: route.path, method, params, query: query });
876
980
  const earlyRenderContext = (status) => {
877
981
  const renderer = rendererFromEvent(event);
878
982
  return renderer ? createViewRenderContext(route, {
@@ -882,8 +986,7 @@ async function handleRouteRequest(registryRoutes, dependencyAliases, route, meth
882
986
  path: url.pathname,
883
987
  params,
884
988
  query: query,
885
- routeUrl,
886
- uiRouteUrl
989
+ routeUrl
887
990
  }, dependencyAliases, renderer, "page", "page", undefined, status) : undefined;
888
991
  };
889
992
  // -- Auth resolution (per spec section 0.5) ----------------------
@@ -952,7 +1055,6 @@ async function handleRouteRequest(registryRoutes, dependencyAliases, route, meth
952
1055
  diagnostic: (diagnostic) => annotateHttpOutcome(event, diagnostic),
953
1056
  serviceId: routerOptions.serviceId,
954
1057
  routeUrl,
955
- uiRouteUrl,
956
1058
  response: responseHelper,
957
1059
  file: fileResponseHelper,
958
1060
  ...(obs ? { obs } : {})
@@ -963,7 +1065,7 @@ async function handleRouteRequest(registryRoutes, dependencyAliases, route, meth
963
1065
  // Streamed representations (NDJSON, themed streaming shell) respond
964
1066
  // directly; buffered representations fall through to the standard
965
1067
  // negotiation over the derived { items, summary? } shape.
966
- const streamed = await handleStreamRepresentation(route, handler, ctx, event, url, method, obs);
1068
+ const streamed = await handleStreamRepresentation(route, handler, ctx, event, url, method, obs, dependencyAliases);
967
1069
  if (streamed) {
968
1070
  applyBpHeadersToEvent(event, bpHeaders);
969
1071
  return streamed;
@@ -1086,7 +1188,7 @@ async function handleRouteRequest(registryRoutes, dependencyAliases, route, meth
1086
1188
  "bp.view.kind": requestedKind,
1087
1189
  "bp.view.status": handlerStatus
1088
1190
  }, () => statusRenderer.render(data, renderContext)));
1089
- return htmlResponse(rewriteServiceRouteTokens(toHtmlString(html), ctx.routeUrl, obs), handlerStatus, htmlContentType("status", methodRoute.chrome));
1191
+ return htmlResponse(toHtmlString(html), handlerStatus, htmlContentType("status", methodRoute.chrome));
1090
1192
  }
1091
1193
  // No specific renderer found.
1092
1194
  if (!shouldFallThroughToDefaultRenderer(handlerStatus)) {
@@ -1120,7 +1222,7 @@ async function handleRouteRequest(registryRoutes, dependencyAliases, route, meth
1120
1222
  "bp.view.kind": "fragment",
1121
1223
  "bp.view.key": fragmentKey
1122
1224
  }, () => resolved.renderer.render(data, renderContext)));
1123
- return htmlResponse(rewriteServiceRouteTokens(toHtmlString(html), ctx.routeUrl, obs), handlerStatus, htmlContentType("fragment", methodRoute.chrome));
1225
+ return htmlResponse(toHtmlString(html), handlerStatus, htmlContentType("fragment", methodRoute.chrome));
1124
1226
  }
1125
1227
  // Component request via `_c` query param
1126
1228
  if (componentId) {
@@ -1143,7 +1245,7 @@ async function handleRouteRequest(registryRoutes, dependencyAliases, route, meth
1143
1245
  "bp.view.kind": "component",
1144
1246
  "bp.view.key": componentId
1145
1247
  }, () => resolved.renderer.render(data, renderContext)));
1146
- return htmlResponse(rewriteServiceRouteTokens(toHtmlString(html), ctx.routeUrl, obs), handlerStatus, htmlContentType("fragment", methodRoute.chrome));
1248
+ return htmlResponse(toHtmlString(html), handlerStatus, htmlContentType("fragment", methodRoute.chrome));
1147
1249
  }
1148
1250
  // Page request - only page renderers allowed
1149
1251
  const resolved = resolveRenderer(route, renderer, "page", method);
@@ -1164,13 +1266,13 @@ async function handleRouteRequest(registryRoutes, dependencyAliases, route, meth
1164
1266
  "bp.view.kind": "page"
1165
1267
  }, () => resolved.renderer.render(data, renderContext)));
1166
1268
  const mode = representation.mode ?? "page";
1167
- return htmlResponse(rewriteServiceRouteTokens(toHtmlString(html), ctx.routeUrl, obs), handlerStatus, htmlContentType(mode, methodRoute.chrome));
1269
+ return htmlResponse(toHtmlString(html), handlerStatus, htmlContentType(mode, methodRoute.chrome));
1168
1270
  }
1169
1271
  /**
1170
1272
  * Handle representations that stream, returning null for buffered ones so the
1171
1273
  * caller falls through to standard negotiation over `{ items, summary? }`.
1172
1274
  */
1173
- async function handleStreamRepresentation(route, handler, ctx, event, url, method, obs) {
1275
+ async function handleStreamRepresentation(route, handler, ctx, event, url, method, obs, dependencyAliases = {}) {
1174
1276
  const acceptHeader = acceptHeaderFromEvent(event);
1175
1277
  const representation = resolveRequestedRepresentation(acceptHeader);
1176
1278
  if (representation.kind === "ndjson") {
@@ -1201,8 +1303,8 @@ async function handleStreamRepresentation(route, handler, ctx, event, url, metho
1201
1303
  "bp.route.view_id": route.viewId,
1202
1304
  "bp.view.renderer": renderer,
1203
1305
  "bp.view.kind": "stream-shell"
1204
- }, () => streamSet.renderShell(shellCtx)));
1205
- return htmlResponse(rewriteServiceRouteTokens(toHtmlString(html), ctx.routeUrl, obs), 200, htmlContentType("fragment", route.methodRoutes?.[method]?.chrome));
1306
+ }, () => streamSet.renderShell(shellCtx, createViewRenderContext(route, ctx, dependencyAliases, renderer, "fragment", "page", undefined, 200))));
1307
+ return htmlResponse(toHtmlString(html), 200, htmlContentType("fragment", route.methodRoutes?.[method]?.chrome));
1206
1308
  }
1207
1309
  /**
1208
1310
  * SSE delivery of the frame stream at `{path}/__sse`. With a theme context and
@@ -1216,6 +1318,7 @@ async function handleStreamSse(registryRoutes, dependencyAliases, route, handler
1216
1318
  return ctx;
1217
1319
  const renderer = rendererFromEvent(event);
1218
1320
  const streamSet = renderer ? route.renderers[renderer]?.stream : undefined;
1321
+ const renderContext = streamSet && renderer ? createViewRenderContext(route, ctx, dependencyAliases, renderer, "fragment", "page", undefined, 200) : undefined;
1219
1322
  const stream = createEventStream(event);
1220
1323
  (async () => {
1221
1324
  try {
@@ -1226,7 +1329,7 @@ async function handleStreamSse(registryRoutes, dependencyAliases, route, handler
1226
1329
  await stream.push({
1227
1330
  event: "item",
1228
1331
  data: streamSet
1229
- ? rewriteServiceRouteTokens(toHtmlString(streamSet.renderItem(item)), ctx.routeUrl, obs)
1332
+ ? toHtmlString(streamSet.renderItem(item, renderContext))
1230
1333
  : JSON.stringify({ kind: "item", data: item })
1231
1334
  });
1232
1335
  },
@@ -1236,7 +1339,7 @@ async function handleStreamSse(registryRoutes, dependencyAliases, route, handler
1236
1339
  await stream.push({
1237
1340
  event: "summary",
1238
1341
  data: streamSet?.renderSummary
1239
- ? rewriteServiceRouteTokens(toHtmlString(streamSet.renderSummary(summary)), ctx.routeUrl, obs)
1342
+ ? toHtmlString(streamSet.renderSummary(summary, renderContext))
1240
1343
  : JSON.stringify({ kind: "summary", data: summary })
1241
1344
  });
1242
1345
  },
@@ -1244,7 +1347,7 @@ async function handleStreamSse(registryRoutes, dependencyAliases, route, handler
1244
1347
  await stream.push({
1245
1348
  event: "error",
1246
1349
  data: streamSet?.renderError
1247
- ? rewriteServiceRouteTokens(toHtmlString(streamSet.renderError(frame)), ctx.routeUrl, obs)
1350
+ ? toHtmlString(streamSet.renderError(frame, renderContext))
1248
1351
  : JSON.stringify(frame)
1249
1352
  });
1250
1353
  },