@ohhwells/bridge 0.1.152 → 0.1.154

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/dist/index.cjs CHANGED
@@ -7271,6 +7271,21 @@ function applyCustomCodeToHead(content) {
7271
7271
  if (beforeNodes.length > 0) document.head.append(...beforeNodes);
7272
7272
  }
7273
7273
 
7274
+ // src/lib/selectNavContainer.ts
7275
+ function isOnScreen(el) {
7276
+ const rect = el.getBoundingClientRect();
7277
+ if (rect.width <= 0 || rect.height <= 0) return false;
7278
+ if (el.offsetParent !== null) return true;
7279
+ return getComputedStyle(el).position === "fixed";
7280
+ }
7281
+ function findSelectableNavContainer(doc = document) {
7282
+ const visible = Array.from(doc.querySelectorAll("[data-ohw-nav-container]")).filter(isOnScreen);
7283
+ if (visible.length === 0) return null;
7284
+ return visible.reduce(
7285
+ (best, el) => el.getBoundingClientRect().top < best.getBoundingClientRect().top ? el : best
7286
+ );
7287
+ }
7288
+
7274
7289
  // src/ui/ai-tree/aiSectionsManager.tsx
7275
7290
  var import_react_dom = require("react-dom");
7276
7291
  var import_client = require("react-dom/client");
@@ -17020,6 +17035,94 @@ function bindPublishedForms(apiUrl, subdomain, content = {}) {
17020
17035
  );
17021
17036
  }
17022
17037
 
17038
+ // src/lib/outage-beacon.ts
17039
+ var DEDUP_MS = 5 * 60 * 1e3;
17040
+ var lastSent = /* @__PURE__ */ new Map();
17041
+ function apiBase() {
17042
+ return process.env.NEXT_PUBLIC_FLOWOPS_API_URL ?? "https://flowops-backend-staging-2yfdh7pwpq-as.a.run.app";
17043
+ }
17044
+ function bridgeVersion() {
17045
+ try {
17046
+ if (true) {
17047
+ return "0.1.154";
17048
+ }
17049
+ } catch {
17050
+ }
17051
+ if (typeof document !== "undefined") {
17052
+ return document.documentElement.getAttribute("data-ohw-bridge-version") || void 0;
17053
+ }
17054
+ return void 0;
17055
+ }
17056
+ function stampBridgeVersionOnDocument() {
17057
+ if (typeof document === "undefined") {
17058
+ return;
17059
+ }
17060
+ try {
17061
+ const v = true ? "0.1.154" : "";
17062
+ if (v) {
17063
+ document.documentElement.setAttribute("data-ohw-bridge-version", v);
17064
+ window.__OHW_BRIDGE_VERSION__ = v;
17065
+ }
17066
+ } catch {
17067
+ }
17068
+ }
17069
+ var RECOVERABLE_PAGE_ERROR = /Minified React error #(?:418|419|421|422|423|425)\b|Hydration failed because the initial UI does not match|Text content does not match server-rendered HTML|There was an error while hydrating|did not match\. Server:/i;
17070
+ function reportOutageBeacon(args) {
17071
+ if (typeof window === "undefined" || !args.subdomain) {
17072
+ return;
17073
+ }
17074
+ if (args.reason === "page_error" && args.detail && RECOVERABLE_PAGE_ERROR.test(args.detail)) {
17075
+ return;
17076
+ }
17077
+ const key = `${args.subdomain}|${args.reason}`;
17078
+ const now = Date.now();
17079
+ const prev = lastSent.get(key) || 0;
17080
+ if (now - prev < DEDUP_MS) {
17081
+ return;
17082
+ }
17083
+ lastSent.set(key, now);
17084
+ const body = JSON.stringify({
17085
+ subdomain: args.subdomain,
17086
+ reason: args.reason,
17087
+ detail: args.detail?.slice(0, 300),
17088
+ templateId: args.templateId,
17089
+ bridgeVersion: bridgeVersion(),
17090
+ href: typeof location !== "undefined" ? location.href : void 0
17091
+ });
17092
+ const url = `${apiBase()}/api/public/sites/outage-beacon`;
17093
+ try {
17094
+ if (typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function") {
17095
+ const blob = new Blob([body], { type: "application/json" });
17096
+ if (navigator.sendBeacon(url, blob)) {
17097
+ return;
17098
+ }
17099
+ }
17100
+ void fetch(url, {
17101
+ method: "POST",
17102
+ headers: { "Content-Type": "application/json" },
17103
+ body,
17104
+ keepalive: true,
17105
+ cache: "no-store"
17106
+ }).catch(() => {
17107
+ });
17108
+ } catch {
17109
+ }
17110
+ }
17111
+ function armLoaderHangBeacon(subdomain, fetchState, hangMs = 15e3) {
17112
+ if (!subdomain || fetchState !== "loading") {
17113
+ return () => {
17114
+ };
17115
+ }
17116
+ const timer = window.setTimeout(() => {
17117
+ reportOutageBeacon({
17118
+ subdomain,
17119
+ reason: "loader_stuck",
17120
+ detail: `fetchState still loading after ${hangMs}ms`
17121
+ });
17122
+ }, hangMs);
17123
+ return () => window.clearTimeout(timer);
17124
+ }
17125
+
17023
17126
  // src/lib/form-fields.ts
17024
17127
  var FIELD_DEFAULTS = {
17025
17128
  "short-text": { label: "Short text", placeholder: "Type placeholder text..." },
@@ -25405,6 +25508,34 @@ function OhhwellsBridge() {
25405
25508
  const [fetchState, setFetchState] = (0, import_react21.useState)("idle");
25406
25509
  const [showBranding, setShowBranding] = (0, import_react21.useState)(false);
25407
25510
  const autoSaveTimers = (0, import_react21.useRef)(/* @__PURE__ */ new Map());
25511
+ (0, import_react21.useEffect)(() => {
25512
+ stampBridgeVersionOnDocument();
25513
+ }, []);
25514
+ (0, import_react21.useEffect)(() => {
25515
+ if (isEditMode) return;
25516
+ return armLoaderHangBeacon(subdomain, fetchState);
25517
+ }, [isEditMode, subdomain, fetchState]);
25518
+ (0, import_react21.useEffect)(() => {
25519
+ if (isEditMode || !subdomain) return;
25520
+ const onError = (event) => {
25521
+ reportOutageBeacon({
25522
+ subdomain,
25523
+ reason: "page_error",
25524
+ detail: event.message || "window error"
25525
+ });
25526
+ };
25527
+ const onRejection = (event) => {
25528
+ const reason = event.reason;
25529
+ const detail = reason instanceof Error ? reason.message : typeof reason === "string" ? reason : "unhandledrejection";
25530
+ reportOutageBeacon({ subdomain, reason: "page_error", detail });
25531
+ };
25532
+ window.addEventListener("error", onError);
25533
+ window.addEventListener("unhandledrejection", onRejection);
25534
+ return () => {
25535
+ window.removeEventListener("error", onError);
25536
+ window.removeEventListener("unhandledrejection", onRejection);
25537
+ };
25538
+ }, [isEditMode, subdomain]);
25408
25539
  const activeElRef = (0, import_react21.useRef)(null);
25409
25540
  const pointerHeldRef = (0, import_react21.useRef)(false);
25410
25541
  const selectedElRef = (0, import_react21.useRef)(null);
@@ -27661,7 +27792,17 @@ function OhhwellsBridge() {
27661
27792
  const apiUrl = process.env.NEXT_PUBLIC_FLOWOPS_API_URL ?? "https://flowops-backend-staging-2yfdh7pwpq-as.a.run.app";
27662
27793
  const initialPath = pathname;
27663
27794
  fetchedContentPaths.add(`${subdomain}::${initialPath}`);
27664
- fetch(`${apiUrl}/api/public/sites/${subdomain}/content?path=${encodeURIComponent(initialPath)}`, { cache: "no-store" }).then((r2) => r2.ok ? r2.json() : null).then((data) => {
27795
+ fetch(`${apiUrl}/api/public/sites/${subdomain}/content?path=${encodeURIComponent(initialPath)}`, { cache: "no-store" }).then((r2) => {
27796
+ if (!r2.ok) {
27797
+ reportOutageBeacon({
27798
+ subdomain,
27799
+ reason: "content_fetch_failed",
27800
+ detail: `HTTP ${r2.status}`
27801
+ });
27802
+ return null;
27803
+ }
27804
+ return r2.json();
27805
+ }).then((data) => {
27665
27806
  if (cancelled) return;
27666
27807
  const content = data?.content ?? {};
27667
27808
  const branding = Boolean(data?.showBranding);
@@ -27670,7 +27811,12 @@ function OhhwellsBridge() {
27670
27811
  recordOverriddenPaths(subdomain, data?.overriddenPaths);
27671
27812
  setShowBranding(branding);
27672
27813
  return applyContent(content);
27673
- }).catch(() => {
27814
+ }).catch((err) => {
27815
+ reportOutageBeacon({
27816
+ subdomain,
27817
+ reason: "content_fetch_failed",
27818
+ detail: err instanceof Error ? err.message : "fetch failed"
27819
+ });
27674
27820
  }).finally(() => {
27675
27821
  if (!cancelled) setFetchState("done");
27676
27822
  });
@@ -30718,6 +30864,12 @@ function OhhwellsBridge() {
30718
30864
  clearIconSelectionRef.current();
30719
30865
  };
30720
30866
  window.addEventListener("message", handleDeactivate);
30867
+ const handleSelectNav = (e) => {
30868
+ if (e.data?.type !== "ow:select-nav") return;
30869
+ const navContainer = findSelectableNavContainer();
30870
+ if (navContainer) selectFrameRef.current(navContainer);
30871
+ };
30872
+ window.addEventListener("message", handleSelectNav);
30721
30873
  const handleToastAction = (e) => {
30722
30874
  if (e.data?.type !== "ow:toast-action") return;
30723
30875
  const actionId = typeof e.data.actionId === "string" ? e.data.actionId : null;
@@ -31534,6 +31686,7 @@ function OhhwellsBridge() {
31534
31686
  window.removeEventListener("message", handleDeleteSection);
31535
31687
  window.removeEventListener("message", handleDuplicateSection);
31536
31688
  window.removeEventListener("message", handleDeactivate);
31689
+ window.removeEventListener("message", handleSelectNav);
31537
31690
  document.documentElement.removeAttribute("data-ohw-panel-dragging");
31538
31691
  window.removeEventListener("message", handleToastAction);
31539
31692
  window.removeEventListener("message", handleFormCount);
@@ -31831,7 +31984,7 @@ function OhhwellsBridge() {
31831
31984
  postToParent2({
31832
31985
  type: "ow:ready",
31833
31986
  version: "1",
31834
- bridgeVersion: "0.1.152",
31987
+ bridgeVersion: "0.1.154",
31835
31988
  path: pathname,
31836
31989
  nodes: collectEditableNodes(editContentRef.current),
31837
31990
  sections