@ohhwells/bridge 0.1.152 → 0.1.153

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
@@ -17020,6 +17020,94 @@ function bindPublishedForms(apiUrl, subdomain, content = {}) {
17020
17020
  );
17021
17021
  }
17022
17022
 
17023
+ // src/lib/outage-beacon.ts
17024
+ var DEDUP_MS = 5 * 60 * 1e3;
17025
+ var lastSent = /* @__PURE__ */ new Map();
17026
+ function apiBase() {
17027
+ return process.env.NEXT_PUBLIC_FLOWOPS_API_URL ?? "https://flowops-backend-staging-2yfdh7pwpq-as.a.run.app";
17028
+ }
17029
+ function bridgeVersion() {
17030
+ try {
17031
+ if (true) {
17032
+ return "0.1.153";
17033
+ }
17034
+ } catch {
17035
+ }
17036
+ if (typeof document !== "undefined") {
17037
+ return document.documentElement.getAttribute("data-ohw-bridge-version") || void 0;
17038
+ }
17039
+ return void 0;
17040
+ }
17041
+ function stampBridgeVersionOnDocument() {
17042
+ if (typeof document === "undefined") {
17043
+ return;
17044
+ }
17045
+ try {
17046
+ const v = true ? "0.1.153" : "";
17047
+ if (v) {
17048
+ document.documentElement.setAttribute("data-ohw-bridge-version", v);
17049
+ window.__OHW_BRIDGE_VERSION__ = v;
17050
+ }
17051
+ } catch {
17052
+ }
17053
+ }
17054
+ 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;
17055
+ function reportOutageBeacon(args) {
17056
+ if (typeof window === "undefined" || !args.subdomain) {
17057
+ return;
17058
+ }
17059
+ if (args.reason === "page_error" && args.detail && RECOVERABLE_PAGE_ERROR.test(args.detail)) {
17060
+ return;
17061
+ }
17062
+ const key = `${args.subdomain}|${args.reason}`;
17063
+ const now = Date.now();
17064
+ const prev = lastSent.get(key) || 0;
17065
+ if (now - prev < DEDUP_MS) {
17066
+ return;
17067
+ }
17068
+ lastSent.set(key, now);
17069
+ const body = JSON.stringify({
17070
+ subdomain: args.subdomain,
17071
+ reason: args.reason,
17072
+ detail: args.detail?.slice(0, 300),
17073
+ templateId: args.templateId,
17074
+ bridgeVersion: bridgeVersion(),
17075
+ href: typeof location !== "undefined" ? location.href : void 0
17076
+ });
17077
+ const url = `${apiBase()}/api/public/sites/outage-beacon`;
17078
+ try {
17079
+ if (typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function") {
17080
+ const blob = new Blob([body], { type: "application/json" });
17081
+ if (navigator.sendBeacon(url, blob)) {
17082
+ return;
17083
+ }
17084
+ }
17085
+ void fetch(url, {
17086
+ method: "POST",
17087
+ headers: { "Content-Type": "application/json" },
17088
+ body,
17089
+ keepalive: true,
17090
+ cache: "no-store"
17091
+ }).catch(() => {
17092
+ });
17093
+ } catch {
17094
+ }
17095
+ }
17096
+ function armLoaderHangBeacon(subdomain, fetchState, hangMs = 15e3) {
17097
+ if (!subdomain || fetchState !== "loading") {
17098
+ return () => {
17099
+ };
17100
+ }
17101
+ const timer = window.setTimeout(() => {
17102
+ reportOutageBeacon({
17103
+ subdomain,
17104
+ reason: "loader_stuck",
17105
+ detail: `fetchState still loading after ${hangMs}ms`
17106
+ });
17107
+ }, hangMs);
17108
+ return () => window.clearTimeout(timer);
17109
+ }
17110
+
17023
17111
  // src/lib/form-fields.ts
17024
17112
  var FIELD_DEFAULTS = {
17025
17113
  "short-text": { label: "Short text", placeholder: "Type placeholder text..." },
@@ -25405,6 +25493,34 @@ function OhhwellsBridge() {
25405
25493
  const [fetchState, setFetchState] = (0, import_react21.useState)("idle");
25406
25494
  const [showBranding, setShowBranding] = (0, import_react21.useState)(false);
25407
25495
  const autoSaveTimers = (0, import_react21.useRef)(/* @__PURE__ */ new Map());
25496
+ (0, import_react21.useEffect)(() => {
25497
+ stampBridgeVersionOnDocument();
25498
+ }, []);
25499
+ (0, import_react21.useEffect)(() => {
25500
+ if (isEditMode) return;
25501
+ return armLoaderHangBeacon(subdomain, fetchState);
25502
+ }, [isEditMode, subdomain, fetchState]);
25503
+ (0, import_react21.useEffect)(() => {
25504
+ if (isEditMode || !subdomain) return;
25505
+ const onError = (event) => {
25506
+ reportOutageBeacon({
25507
+ subdomain,
25508
+ reason: "page_error",
25509
+ detail: event.message || "window error"
25510
+ });
25511
+ };
25512
+ const onRejection = (event) => {
25513
+ const reason = event.reason;
25514
+ const detail = reason instanceof Error ? reason.message : typeof reason === "string" ? reason : "unhandledrejection";
25515
+ reportOutageBeacon({ subdomain, reason: "page_error", detail });
25516
+ };
25517
+ window.addEventListener("error", onError);
25518
+ window.addEventListener("unhandledrejection", onRejection);
25519
+ return () => {
25520
+ window.removeEventListener("error", onError);
25521
+ window.removeEventListener("unhandledrejection", onRejection);
25522
+ };
25523
+ }, [isEditMode, subdomain]);
25408
25524
  const activeElRef = (0, import_react21.useRef)(null);
25409
25525
  const pointerHeldRef = (0, import_react21.useRef)(false);
25410
25526
  const selectedElRef = (0, import_react21.useRef)(null);
@@ -27661,7 +27777,17 @@ function OhhwellsBridge() {
27661
27777
  const apiUrl = process.env.NEXT_PUBLIC_FLOWOPS_API_URL ?? "https://flowops-backend-staging-2yfdh7pwpq-as.a.run.app";
27662
27778
  const initialPath = pathname;
27663
27779
  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) => {
27780
+ fetch(`${apiUrl}/api/public/sites/${subdomain}/content?path=${encodeURIComponent(initialPath)}`, { cache: "no-store" }).then((r2) => {
27781
+ if (!r2.ok) {
27782
+ reportOutageBeacon({
27783
+ subdomain,
27784
+ reason: "content_fetch_failed",
27785
+ detail: `HTTP ${r2.status}`
27786
+ });
27787
+ return null;
27788
+ }
27789
+ return r2.json();
27790
+ }).then((data) => {
27665
27791
  if (cancelled) return;
27666
27792
  const content = data?.content ?? {};
27667
27793
  const branding = Boolean(data?.showBranding);
@@ -27670,7 +27796,12 @@ function OhhwellsBridge() {
27670
27796
  recordOverriddenPaths(subdomain, data?.overriddenPaths);
27671
27797
  setShowBranding(branding);
27672
27798
  return applyContent(content);
27673
- }).catch(() => {
27799
+ }).catch((err) => {
27800
+ reportOutageBeacon({
27801
+ subdomain,
27802
+ reason: "content_fetch_failed",
27803
+ detail: err instanceof Error ? err.message : "fetch failed"
27804
+ });
27674
27805
  }).finally(() => {
27675
27806
  if (!cancelled) setFetchState("done");
27676
27807
  });
@@ -31831,7 +31962,7 @@ function OhhwellsBridge() {
31831
31962
  postToParent2({
31832
31963
  type: "ow:ready",
31833
31964
  version: "1",
31834
- bridgeVersion: "0.1.152",
31965
+ bridgeVersion: "0.1.153",
31835
31966
  path: pathname,
31836
31967
  nodes: collectEditableNodes(editContentRef.current),
31837
31968
  sections