@octostar/platform-api 0.5.31 → 0.5.32

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.
@@ -22471,7 +22471,14 @@ exports.default = _default;
22471
22471
  Object.defineProperty(exports, "__esModule", {
22472
22472
  value: true
22473
22473
  });
22474
- exports.savedSearchApi = exports.remoteAppApi = exports.ontologyApi = exports.getOntologyApi = exports.getDesktopApi = exports.getContextApi = exports.extrasApi = exports.desktopApi = exports.contextApi = void 0;
22474
+ exports.getDesktopApi = exports.getContextApi = exports.extrasApi = exports.desktopApi = exports.contextApi = void 0;
22475
+ Object.defineProperty(exports, "getOctostarConnectionManager", {
22476
+ enumerable: true,
22477
+ get: function get() {
22478
+ return _factory.getOctostarConnectionManager;
22479
+ }
22480
+ });
22481
+ exports.savedSearchApi = exports.remoteAppApi = exports.ontologyApi = exports.getOntologyApi = void 0;
22475
22482
  var _AsyncServiceLocator = require("./lib/AsyncServiceLocator");
22476
22483
  var _factory = require("./factory");
22477
22484
  var _constants = require("./constants");
@@ -22593,6 +22600,11 @@ var getContextApi = exports.getContextApi = /*#__PURE__*/function () {
22593
22600
  return _ref3.apply(this, arguments);
22594
22601
  };
22595
22602
  }();
22603
+ /**
22604
+ * @beta
22605
+ * Gets the singleton instance of OctostarConnectionManager.
22606
+ * This is the primary way to access connection management functionality.
22607
+ */
22596
22608
 
22597
22609
  },{"./constants":34,"./factory":35,"./lib/AsyncServiceLocator":39}],24:[function(require,module,exports){
22598
22610
  "use strict";
@@ -23722,226 +23734,610 @@ var OCTOSTAR_ENTITIES_MIME_TYPE = exports.OCTOSTAR_ENTITIES_MIME_TYPE = 'applica
23722
23734
  },{}],35:[function(require,module,exports){
23723
23735
  "use strict";
23724
23736
 
23725
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
23726
23737
  Object.defineProperty(exports, "__esModule", {
23727
23738
  value: true
23728
23739
  });
23729
- exports.forwardCallsToFutureObject = exports.createRemoteApiHandle = void 0;
23740
+ exports.forwardCallsToFutureObject = exports.createRemoteApiHandle = exports.OctostarConnectionManager = void 0;
23741
+ exports.getOctostarConnectionManager = getOctostarConnectionManager;
23730
23742
  var postRobot = _interopRequireWildcard(require("post-robot"));
23731
23743
  var _utils = require("./utils");
23732
23744
  var _constants = require("./constants");
23733
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t2 in e) "default" !== _t2 && {}.hasOwnProperty.call(e, _t2) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t2)) && (i.get || i.set) ? o(f, _t2, i) : f[_t2] = e[_t2]); return f; })(e, t); }
23745
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
23746
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
23734
23747
  function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
23735
23748
  function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
23736
23749
  function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
23737
23750
  function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
23738
- function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
23739
23751
  function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
23740
23752
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
23741
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
23742
23753
  function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
23743
23754
  function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
23755
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
23756
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
23744
23757
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
23745
- var hasParent = function hasParent(window) {
23746
- return window.parent !== window;
23747
- };
23748
- function getOctostarWindow(channelId) {
23749
- var currentWindow = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window;
23750
- var depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
23751
- // Check all iframes in the current window
23752
- var iframes;
23753
- try {
23754
- iframes = currentWindow.document.querySelectorAll('iframe');
23755
- } catch (e) {
23756
- // assuming cross-origin iframe
23757
- return currentWindow;
23758
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
23759
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
23760
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
23761
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
23762
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
23763
+ /**
23764
+ * Manages Octostar connection state, including remote dev mode, channel IDs, window references,
23765
+ * and connection lifecycle. This is a singleton class accessed via getOctostarConnectionManager().
23766
+ */
23767
+ var OctostarConnectionManager = exports.OctostarConnectionManager = /*#__PURE__*/function () {
23768
+ function OctostarConnectionManager() {
23769
+ _classCallCheck(this, OctostarConnectionManager);
23770
+ this.remoteDevWindow = null;
23771
+ this.channelIdSubscribers = new Set();
23758
23772
  }
23759
- for (var i = 0; i < iframes.length; i += 1) {
23760
- var iframe = iframes[i];
23761
- if (iframe.getAttribute('data-octostar-iframe') === 'true' && iframe.getAttribute('data-octostar-iframe-channel') === channelId) {
23762
- return currentWindow;
23773
+ /* ------------------------------------------------------------------ */
23774
+ /* Private Helpers */
23775
+ /* ------------------------------------------------------------------ */
23776
+ return _createClass(OctostarConnectionManager, [{
23777
+ key: "hasParent",
23778
+ value: function hasParent(window) {
23779
+ return window.parent !== window;
23763
23780
  }
23764
- }
23765
- // Check if we've reached the top window
23766
- if (!hasParent(currentWindow)) {
23767
- console.error('Top window reached without finding the Octostar window. You are trying to view the app from outside Octostar?');
23768
- // could be an old version of Octostar?
23769
- return currentWindow;
23770
- }
23771
- // Prevent infinite loops or excessive searching
23772
- if (depth > 25) {
23773
- throw new Error('Max depth reached. Octostar window not found.');
23774
- }
23775
- // If not found, continue searching in the parent window
23776
- return getOctostarWindow(channelId, currentWindow.parent, depth + 1);
23777
- }
23778
- var handlePostResponse = function handlePostResponse(response) {
23779
- if (response.data.error) {
23780
- throw new Error(response.data.error.message);
23781
- }
23782
- return response.data.data;
23783
- };
23784
- var createObjectProxy = function createObjectProxy(value, options) {
23785
- return new Proxy(value, {
23786
- get: function get(target, prop) {
23787
- // This construction does not support nested objects
23788
- if (typeof target[prop] === 'function') {
23789
- return new Proxy(target[prop], {
23790
- apply: function apply(methodTarget, _, args) {
23791
- var callResult = methodTarget.apply(void 0, _toConsumableArray(args));
23792
- var isPromise = callResult instanceof Promise;
23793
- var isPromiseLike = typeof (callResult === null || callResult === void 0 ? void 0 : callResult.then) === 'function' && typeof (callResult === null || callResult === void 0 ? void 0 : callResult["catch"]) === 'function';
23794
- if (isPromise || isPromiseLike) {
23795
- return callResult["catch"](function (e) {
23796
- var methodFullPath = "".concat(options.name, ".").concat(prop, "()");
23797
- var error = new Error("Error calling ".concat(methodFullPath, ": ").concat(e.message));
23798
- error.stack = "at ".concat(methodFullPath, ": ").concat(e.stack);
23799
- error.originalError = e;
23800
- throw error;
23801
- });
23781
+ }, {
23782
+ key: "getParentOctostarWindow",
23783
+ value: function getParentOctostarWindow(channelId) {
23784
+ var currentWindow = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window;
23785
+ var depth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
23786
+ var iframes;
23787
+ try {
23788
+ iframes = currentWindow.document.querySelectorAll('iframe');
23789
+ } catch (_unused) {
23790
+ return currentWindow;
23791
+ }
23792
+ var _iterator = _createForOfIteratorHelper(iframes),
23793
+ _step;
23794
+ try {
23795
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
23796
+ var iframe = _step.value;
23797
+ if (iframe.getAttribute('data-octostar-iframe') === 'true' && iframe.getAttribute('data-octostar-iframe-channel') === channelId) {
23798
+ return currentWindow;
23799
+ }
23800
+ }
23801
+ } catch (err) {
23802
+ _iterator.e(err);
23803
+ } finally {
23804
+ _iterator.f();
23805
+ }
23806
+ if (!this.hasParent(currentWindow)) {
23807
+ return undefined;
23808
+ }
23809
+ if (depth > 25) {
23810
+ return undefined;
23811
+ }
23812
+ return this.getParentOctostarWindow(channelId, currentWindow.parent, depth + 1);
23813
+ }
23814
+ }, {
23815
+ key: "tryFetchingFromAttributes",
23816
+ value: function tryFetchingFromAttributes(currentWindow) {
23817
+ try {
23818
+ var iframes = currentWindow.parent.document.getElementsByTagName('iframe');
23819
+ var _iterator2 = _createForOfIteratorHelper(iframes),
23820
+ _step2;
23821
+ try {
23822
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
23823
+ var iframe = _step2.value;
23824
+ if (iframe.contentWindow === currentWindow) {
23825
+ var _iframe$getAttribute;
23826
+ return (_iframe$getAttribute = iframe.getAttribute('data-octostar-iframe-channel')) !== null && _iframe$getAttribute !== void 0 ? _iframe$getAttribute : undefined;
23802
23827
  }
23803
- return callResult;
23804
23828
  }
23805
- });
23829
+ } catch (err) {
23830
+ _iterator2.e(err);
23831
+ } finally {
23832
+ _iterator2.f();
23833
+ }
23834
+ } catch (_unused2) {
23835
+ /* ignore */
23806
23836
  }
23807
- return target[prop];
23837
+ return undefined;
23808
23838
  }
23809
- });
23810
- };
23811
- function tryFetchingFomAttributes(currentWindow) {
23812
- try {
23813
- var iframes = currentWindow.parent.document.getElementsByTagName('iframe');
23814
- var _iterator = _createForOfIteratorHelper(iframes),
23815
- _step;
23816
- try {
23817
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
23818
- var iframe = _step.value;
23819
- if (iframe.contentWindow === currentWindow) {
23820
- var channelId = iframe.getAttribute('data-octostar-iframe-channel');
23821
- if (channelId) {
23822
- console.log("PostRobot: Setting channelId from iframe attribute ".concat(channelId));
23823
- window.octostarChannelId = channelId;
23824
- return channelId;
23839
+ }, {
23840
+ key: "traverseForChannelId",
23841
+ value: function traverseForChannelId() {
23842
+ var currentWindow = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window;
23843
+ var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
23844
+ if (depth > 25) return undefined;
23845
+ // Try to read octostarChannelId from window, but handle SecurityError for cross-origin windows
23846
+ try {
23847
+ if (currentWindow.octostarChannelId) {
23848
+ return currentWindow.octostarChannelId;
23849
+ }
23850
+ } catch (_unused3) {
23851
+ // SecurityError on cross-origin windows - continue to fallback mechanisms
23852
+ }
23853
+ // Try to get channelId from URL query params
23854
+ try {
23855
+ if (currentWindow.location.search) {
23856
+ var params = new URLSearchParams(currentWindow.location.search);
23857
+ var fromQuery = params.get('octostarChannelId');
23858
+ if (fromQuery) {
23859
+ window.octostarChannelId = fromQuery;
23860
+ return fromQuery;
23825
23861
  }
23826
23862
  }
23863
+ } catch (_unused4) {
23864
+ // Cross-origin iframe - can't access location
23865
+ // Continue to try other methods
23866
+ }
23867
+ // Try fetching from iframe attributes (only works if we can access parent)
23868
+ try {
23869
+ var fromAttrs = this.tryFetchingFromAttributes(currentWindow);
23870
+ if (fromAttrs) {
23871
+ window.octostarChannelId = fromAttrs;
23872
+ return fromAttrs;
23873
+ }
23874
+ } catch (_unused5) {
23875
+ // Ignore errors
23876
+ }
23877
+ // Try parent window
23878
+ try {
23879
+ return this.traverseForChannelId(currentWindow.parent, depth + 1);
23880
+ } catch (_unused6) {
23881
+ // Cross-origin parent - can't traverse further
23882
+ return undefined;
23827
23883
  }
23828
- } catch (err) {
23829
- _iterator.e(err);
23830
- } finally {
23831
- _iterator.f();
23832
23884
  }
23833
- return undefined;
23834
- } catch (e) {
23835
- // Ignore errors, maybe cross-origin iframes
23836
- return undefined;
23837
- }
23838
- }
23839
- function traverseForChannelId() {
23840
- var currentWindow = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window;
23841
- var depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
23842
- // Prevent infinite loops or excessive searching
23843
- if (depth > 25) {
23844
- throw new Error('PostRobot: Max depth reached. octostarChannelId not found.');
23845
- }
23846
- // Try to access octostarChannelId, but handle cross-origin errors
23847
- try {
23848
- if (currentWindow.octostarChannelId) {
23849
- return currentWindow.octostarChannelId;
23885
+ }, {
23886
+ key: "clearConnectionHistory",
23887
+ value: function clearConnectionHistory() {
23888
+ sessionStorage.removeItem('octostarRemoteDevWasConnected');
23889
+ sessionStorage.removeItem('octostarRemoteDevIntentionallyDisconnected');
23850
23890
  }
23851
- } catch (e) {
23852
- // Cross-origin iframe - can't access window properties
23853
- // Continue to try other methods
23854
- }
23855
- try {
23856
- // Try to get channelId from URL query params
23857
- if (currentWindow.location.search) {
23858
- var urlParams = new URLSearchParams(currentWindow.location.search);
23859
- var channelId = urlParams.get('octostarChannelId');
23860
- if (channelId) {
23861
- console.log("PostRobot: Setting channelId from queryParams ".concat(channelId));
23862
- window.octostarChannelId = channelId;
23863
- return channelId;
23891
+ }, {
23892
+ key: "notifyChannelIdChanged",
23893
+ value: function notifyChannelIdChanged(channelId) {
23894
+ this.channelIdSubscribers.forEach(function (callback) {
23895
+ callback(channelId);
23896
+ });
23897
+ }
23898
+ }, {
23899
+ key: "handlePostResponse",
23900
+ value: function handlePostResponse(response) {
23901
+ if (response.data.error) {
23902
+ throw new Error(response.data.error.message);
23864
23903
  }
23904
+ return response.data.data;
23865
23905
  }
23866
- } catch (e) {
23867
- // Cross-origin iframe - can't access location
23868
- // Continue to try other methods
23869
- }
23870
- // Try fetching from iframe attributes (only works if we can access parent)
23871
- try {
23872
- var _channelId = tryFetchingFomAttributes(currentWindow);
23873
- if (_channelId) {
23874
- return _channelId;
23906
+ }, {
23907
+ key: "createObjectProxy",
23908
+ value: function createObjectProxy(value, options) {
23909
+ return new Proxy(value, {
23910
+ get: function get(target, prop) {
23911
+ if (typeof target[prop] === 'function') {
23912
+ return new Proxy(target[prop], {
23913
+ apply: function apply(methodTarget, _, args) {
23914
+ var result = methodTarget.apply(void 0, _toConsumableArray(args));
23915
+ if (result !== null && result !== void 0 && result.then) {
23916
+ return result["catch"](function (e) {
23917
+ var path = "".concat(options.name, ".").concat(String(prop), "()");
23918
+ var err = new Error("Error calling ".concat(path, ": ").concat(e.message));
23919
+ err.originalError = e;
23920
+ throw err;
23921
+ });
23922
+ }
23923
+ return result;
23924
+ }
23925
+ });
23926
+ }
23927
+ return target[prop];
23928
+ }
23929
+ });
23875
23930
  }
23876
- } catch (e) {
23877
- // Ignore errors
23878
- }
23879
- // Try parent window
23880
- try {
23881
- return traverseForChannelId(currentWindow.parent, depth + 1);
23882
- } catch (e) {
23883
- // Cross-origin parent - can't traverse further
23884
- console.error('PostRobot: Cannot traverse to parent window (cross-origin)', e);
23885
- return undefined;
23931
+ /* ------------------------------------------------------------------ */
23932
+ /* Public API - Window Management */
23933
+ /* ------------------------------------------------------------------ */
23934
+ /**
23935
+ * Sets the remote dev window reference.
23936
+ * This should be called when opening a remote dev window from a React component.
23937
+ */
23938
+ }, {
23939
+ key: "setWindow",
23940
+ value: function setWindow(window) {
23941
+ this.remoteDevWindow = window;
23942
+ }
23943
+ /**
23944
+ * Gets the remote dev window reference.
23945
+ */
23946
+ }, {
23947
+ key: "getWindow",
23948
+ value: function getWindow() {
23949
+ return this.remoteDevWindow;
23950
+ }
23951
+ /* ------------------------------------------------------------------ */
23952
+ /* Public API - Channel ID Management */
23953
+ /* ------------------------------------------------------------------ */
23954
+ /**
23955
+ * Gets or creates a remote dev channel ID.
23956
+ * If a channel ID already exists in sessionStorage, returns it.
23957
+ * Otherwise, generates a new one and stores it.
23958
+ */
23959
+ }, {
23960
+ key: "getOrCreateChannelId",
23961
+ value: function getOrCreateChannelId() {
23962
+ var key = 'octostarRemoteDevChannelId';
23963
+ var existing = sessionStorage.getItem(key);
23964
+ if (existing) return existing;
23965
+ var generated = typeof crypto !== 'undefined' && 'randomUUID' in crypto ? crypto.randomUUID() : "rd-".concat(Date.now(), "-").concat(Math.random().toString(16).slice(2));
23966
+ sessionStorage.setItem(key, generated);
23967
+ return generated;
23968
+ }
23969
+ /**
23970
+ * Checks if a remote dev channel ID exists without creating one.
23971
+ * Used to determine if a connection attempt has been made.
23972
+ */
23973
+ }, {
23974
+ key: "hasChannelId",
23975
+ value: function hasChannelId() {
23976
+ var key = 'octostarRemoteDevChannelId';
23977
+ return sessionStorage.getItem(key) !== null;
23978
+ }
23979
+ /**
23980
+ * Subscribe to remote dev channel ID changes.
23981
+ * Returns an unsubscribe function.
23982
+ */
23983
+ }, {
23984
+ key: "onChannelIdChanged",
23985
+ value: function onChannelIdChanged(callback) {
23986
+ var _this = this;
23987
+ this.channelIdSubscribers.add(callback);
23988
+ return function () {
23989
+ return _this.channelIdSubscribers["delete"](callback);
23990
+ };
23991
+ }
23992
+ /* ------------------------------------------------------------------ */
23993
+ /* Public API - Connection State */
23994
+ /* ------------------------------------------------------------------ */
23995
+ /**
23996
+ * Marks that a successful remote dev connection was established.
23997
+ * This is called when a connection is successfully made (e.g., ping succeeds).
23998
+ */
23999
+ }, {
24000
+ key: "markConnectionSuccess",
24001
+ value: function markConnectionSuccess() {
24002
+ sessionStorage.setItem('octostarRemoteDevWasConnected', 'true');
24003
+ // Clear intentional disconnect flag since we're now connected
24004
+ sessionStorage.removeItem('octostarRemoteDevIntentionallyDisconnected');
24005
+ }
24006
+ /**
24007
+ * Marks whether the remote dev connection was intentionally disconnected.
24008
+ * @param intentionallyDisconnected - true if user clicked Disconnect/Reset, false if user is trying to connect
24009
+ */
24010
+ }, {
24011
+ key: "markIntentionallyDisconnected",
24012
+ value: function markIntentionallyDisconnected(intentionallyDisconnected) {
24013
+ if (intentionallyDisconnected) {
24014
+ sessionStorage.setItem('octostarRemoteDevIntentionallyDisconnected', 'true');
24015
+ } else {
24016
+ sessionStorage.removeItem('octostarRemoteDevIntentionallyDisconnected');
24017
+ }
24018
+ }
24019
+ /**
24020
+ * Returns whether a successful remote dev connection was ever established in this session.
24021
+ * This persists across component remounts and page refreshes (within the same session).
24022
+ * Only returns true if a channel ID exists (fixes initial load bug).
24023
+ */
24024
+ }, {
24025
+ key: "wasEverConnected",
24026
+ value: function wasEverConnected() {
24027
+ // Only return true if we have evidence of a connection attempt (channel ID exists)
24028
+ // This prevents showing "CONNECTION LOST" on initial load when sessionStorage has stale data
24029
+ return this.hasChannelId() && sessionStorage.getItem('octostarRemoteDevWasConnected') === 'true';
24030
+ }
24031
+ /**
24032
+ * Returns whether the remote dev connection was intentionally disconnected.
24033
+ * This is used to determine whether to show "Connect" vs "Reconnect" button.
24034
+ */
24035
+ }, {
24036
+ key: "wasIntentionallyDisconnected",
24037
+ value: function wasIntentionallyDisconnected() {
24038
+ return sessionStorage.getItem('octostarRemoteDevIntentionallyDisconnected') === 'true';
24039
+ }
24040
+ /* ------------------------------------------------------------------ */
24041
+ /* Public API - URL Management */
24042
+ /* ------------------------------------------------------------------ */
24043
+ /**
24044
+ * Gets the remote dev URL from sessionStorage.
24045
+ * Returns empty string if not set.
24046
+ */
24047
+ }, {
24048
+ key: "getUrl",
24049
+ value: function getUrl() {
24050
+ return sessionStorage.getItem('octostarRemoteDevUrl') || '';
24051
+ }
24052
+ /**
24053
+ * Sets the remote dev URL in sessionStorage.
24054
+ */
24055
+ }, {
24056
+ key: "setUrl",
24057
+ value: function setUrl(url) {
24058
+ sessionStorage.setItem('octostarRemoteDevUrl', url);
24059
+ }
24060
+ /* ------------------------------------------------------------------ */
24061
+ /* Public API - Mode Detection */
24062
+ /* ------------------------------------------------------------------ */
24063
+ /**
24064
+ * Returns true when the app is not in connected iframe mode (no octostarChannelId found in URL or
24065
+ * iframe chain), i.e. running in remote dev mode. Returns false when running inside an Octostar
24066
+ * iframe (embedded).
24067
+ */
24068
+ }, {
24069
+ key: "isRemoteDevMode",
24070
+ value: function isRemoteDevMode() {
24071
+ if (this.resolvedMode) {
24072
+ return this.resolvedMode.mode === 'remote';
24073
+ }
24074
+ return this.traverseForChannelId() === undefined;
24075
+ }
24076
+ /* ------------------------------------------------------------------ */
24077
+ /* Public API - Connection Lifecycle */
24078
+ /* ------------------------------------------------------------------ */
24079
+ /**
24080
+ * Clears resolvedMode if the channel ID has changed.
24081
+ * This is called when SET_CHANNEL_ID message is received to ensure
24082
+ * createRemoteApiHandle re-resolves with the new channel ID.
24083
+ * @param newChannelId - The new channel ID that was set
24084
+ */
24085
+ }, {
24086
+ key: "clearResolvedModeIfChannelChanged",
24087
+ value: function clearResolvedModeIfChannelChanged(newChannelId) {
24088
+ if (this.resolvedMode && this.resolvedMode.mode === 'iframe') {
24089
+ if (this.resolvedMode.channelId !== newChannelId) {
24090
+ console.log('PostRobot: channel ID changed, clearing cached resolvedMode', {
24091
+ old: this.resolvedMode.channelId,
24092
+ "new": newChannelId
24093
+ });
24094
+ this.resolvedMode = undefined;
24095
+ }
24096
+ }
24097
+ }
24098
+ /**
24099
+ * Resets the remote dev connection state.
24100
+ * This clears the resolved mode and window reference, allowing the connection to be re-established.
24101
+ * Should be called when connection is lost and user wants to reconnect.
24102
+ */
24103
+ }, {
24104
+ key: "resetConnection",
24105
+ value: function resetConnection() {
24106
+ // Clear resolved mode to force re-resolution on next API call
24107
+ this.resolvedMode = undefined;
24108
+ // Clear remote dev window if it's closed
24109
+ if (this.remoteDevWindow && this.remoteDevWindow.closed) {
24110
+ this.remoteDevWindow = null;
24111
+ }
24112
+ }
24113
+ /**
24114
+ * Resets remote dev mode by closing the window and clearing all connection state.
24115
+ * This puts the app back into a disconnected startup state.
24116
+ * A new channel ID will be generated automatically when the user clicks Connect.
24117
+ */
24118
+ }, {
24119
+ key: "resetMode",
24120
+ value: function resetMode() {
24121
+ // Close the remote dev window if it's open
24122
+ if (this.remoteDevWindow && !this.remoteDevWindow.closed) {
24123
+ this.remoteDevWindow.close();
24124
+ }
24125
+ // Get the old channel ID before clearing it, so we can clear its cached app mapping
24126
+ var oldChannelId = sessionStorage.getItem('octostarRemoteDevChannelId');
24127
+ // Clear the old channel ID from sessionStorage
24128
+ sessionStorage.removeItem('octostarRemoteDevChannelId');
24129
+ // Clear the cached app entity mapping for the old channel ID
24130
+ // Note: mappings are stored in localStorage (not sessionStorage) to persist across tab closes
24131
+ // Only clear the mapping for this specific channel to avoid invalidating other active remote dev sessions
24132
+ if (oldChannelId) {
24133
+ var mappingKey = "octostarRemoteDevMapping-".concat(oldChannelId);
24134
+ localStorage.removeItem(mappingKey);
24135
+ }
24136
+ // Clear resolved mode to force re-resolution on next API call
24137
+ this.resolvedMode = undefined;
24138
+ // Clear remote dev window reference
24139
+ this.remoteDevWindow = null;
24140
+ // Clear connection history
24141
+ this.clearConnectionHistory();
24142
+ // Don't generate a new channel ID or notify subscribers here
24143
+ // A new channel ID will be created when openWindow() is called
24144
+ }
24145
+ /**
24146
+ * Opens a remote dev window with the given URL.
24147
+ * This function:
24148
+ * - Validates the URL
24149
+ * - Saves it to sessionStorage
24150
+ * - Gets or creates a channel ID
24151
+ * - Adds remoteDevChannelId as a URL parameter
24152
+ * - Opens the window and stores the reference
24153
+ * - Returns the window or null if popup was blocked
24154
+ */
24155
+ }, {
24156
+ key: "openWindow",
24157
+ value: function openWindow(url) {
24158
+ if (!url) {
24159
+ return null;
24160
+ }
24161
+ // Save URL to sessionStorage
24162
+ this.setUrl(url);
24163
+ // Mark that user is trying to connect (not intentionally disconnected)
24164
+ this.markIntentionallyDisconnected(false);
24165
+ // Check if channel ID already exists
24166
+ var key = 'octostarRemoteDevChannelId';
24167
+ var existingChannelId = sessionStorage.getItem(key);
24168
+ // Get or create channel ID
24169
+ var channelId = this.getOrCreateChannelId();
24170
+ // Notify subscribers if this is a new channel ID (created after reset)
24171
+ if (!existingChannelId) {
24172
+ this.notifyChannelIdChanged(channelId);
24173
+ }
24174
+ // Add remoteDevChannelId as a URL parameter
24175
+ var urlObj;
24176
+ try {
24177
+ urlObj = new URL(url);
24178
+ } catch (error) {
24179
+ // Invalid URL - return null to indicate failure (consistent with popup blocked behavior)
24180
+ return null;
24181
+ }
24182
+ urlObj.searchParams.set('remoteDevChannelId', channelId);
24183
+ // Open window
24184
+ var win = window.open(urlObj.toString(), channelId);
24185
+ if (!win) {
24186
+ return null;
24187
+ }
24188
+ // Store window reference
24189
+ this.setWindow(win);
24190
+ return win;
24191
+ }
24192
+ /* ------------------------------------------------------------------ */
24193
+ /* Public API - API Creation */
24194
+ /* ------------------------------------------------------------------ */
24195
+ /**
24196
+ * Creates a remote API handle for communicating with Octostar.
24197
+ * This resolves the connection mode (iframe vs remote dev) and sets up post-robot communication.
24198
+ */
24199
+ }, {
24200
+ key: "createRemoteApiHandle",
24201
+ value: (function () {
24202
+ var _createRemoteApiHandle = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(params) {
24203
+ var _this2 = this;
24204
+ var iframeChannelId, _targetWindow, _targetWindow3, _channelId, _targetWindow2, _this$resolvedMode, channelId, targetWindow, mode, topic, retryOptions, response, api;
24205
+ return _regenerator().w(function (_context) {
24206
+ while (1) switch (_context.n) {
24207
+ case 0:
24208
+ if (this.resolvedMode) {
24209
+ _context.n = 4;
24210
+ break;
24211
+ }
24212
+ iframeChannelId = this.traverseForChannelId();
24213
+ if (!iframeChannelId) {
24214
+ _context.n = 2;
24215
+ break;
24216
+ }
24217
+ _targetWindow = this.getParentOctostarWindow(iframeChannelId);
24218
+ if (_targetWindow) {
24219
+ _context.n = 1;
24220
+ break;
24221
+ }
24222
+ throw new Error('PostRobot: iframe channel found but no Octostar window');
24223
+ case 1:
24224
+ this.resolvedMode = {
24225
+ mode: 'iframe',
24226
+ channelId: iframeChannelId,
24227
+ targetWindow: _targetWindow
24228
+ };
24229
+ _context.n = 4;
24230
+ break;
24231
+ case 2:
24232
+ _channelId = this.getOrCreateChannelId();
24233
+ _targetWindow2 = this.remoteDevWindow; // Check if existing window is closed, and clear it if so
24234
+ if ((_targetWindow3 = _targetWindow2) !== null && _targetWindow3 !== void 0 && _targetWindow3.closed) {
24235
+ this.remoteDevWindow = null;
24236
+ _targetWindow2 = null;
24237
+ }
24238
+ if (_targetWindow2) {
24239
+ _context.n = 3;
24240
+ break;
24241
+ }
24242
+ throw new Error('Remote dev window not open. Please click "Connect" or "Reconnect" to open the Octostar window.');
24243
+ case 3:
24244
+ console.log('PostRobot: No iframe detected → remote dev mode', _channelId);
24245
+ this.resolvedMode = {
24246
+ mode: 'remote',
24247
+ channelId: _channelId,
24248
+ targetWindow: _targetWindow2
24249
+ };
24250
+ case 4:
24251
+ _this$resolvedMode = this.resolvedMode, channelId = _this$resolvedMode.channelId, targetWindow = _this$resolvedMode.targetWindow, mode = _this$resolvedMode.mode;
24252
+ topic = (0, _constants.getPostMessageNames)(channelId).get_api;
24253
+ console.debug('PostRobot: sending get_api', topic, params === null || params === void 0 ? void 0 : params.name);
24254
+ // Use different retry parameters based on connection mode:
24255
+ // - iframe mode: fail fast (3 attempts) since parent window should be immediately available
24256
+ // - remote mode: retry many times (100 attempts) since Octostar window may take a while to open
24257
+ retryOptions = mode === 'iframe' ? {
24258
+ maxAttempts: 3,
24259
+ retryInterval: 1000
24260
+ } : {
24261
+ maxAttempts: 100,
24262
+ retryInterval: 1000
24263
+ };
24264
+ _context.n = 5;
24265
+ return (0, _utils.retry)(function () {
24266
+ var _this2$remoteDevWindo;
24267
+ var actualTargetWindow = (_this2$remoteDevWindo = _this2.remoteDevWindow) !== null && _this2$remoteDevWindo !== void 0 ? _this2$remoteDevWindo : targetWindow;
24268
+ return postRobot.send(actualTargetWindow, topic, params);
24269
+ }, retryOptions);
24270
+ case 5:
24271
+ response = _context.v;
24272
+ api = this.handlePostResponse(response);
24273
+ return _context.a(2, this.createObjectProxy(api, {
24274
+ name: params.name
24275
+ }));
24276
+ }
24277
+ }, _callee, this);
24278
+ }));
24279
+ function createRemoteApiHandle(_x) {
24280
+ return _createRemoteApiHandle.apply(this, arguments);
24281
+ }
24282
+ return createRemoteApiHandle;
24283
+ }())
24284
+ }]);
24285
+ }();
24286
+ /* ------------------------------------------------------------------ */
24287
+ /* Singleton Pattern */
24288
+ /* ------------------------------------------------------------------ */
24289
+ var instance = null;
24290
+ /**
24291
+ * Gets the singleton instance of OctostarConnectionManager.
24292
+ * Creates a new instance if one doesn't exist.
24293
+ */
24294
+ function getOctostarConnectionManager() {
24295
+ if (!instance) {
24296
+ instance = new OctostarConnectionManager();
23886
24297
  }
24298
+ return instance;
23887
24299
  }
24300
+ /* ------------------------------------------------------------------ */
24301
+ /* Standalone Functions (used internally) */
24302
+ /* ------------------------------------------------------------------ */
24303
+ // Listen for SET_CHANNEL_ID messages and update channel ID + clear cached resolvedMode
23888
24304
  window.addEventListener('message', function (event) {
23889
24305
  var _event$data;
23890
- if (((_event$data = event.data) === null || _event$data === void 0 ? void 0 : _event$data.type) === 'SET_CHANNEL_ID') {
23891
- window.octostarChannelId = event.data.channelId;
23892
- console.log('PostRobot: received channelId', event.data.channelId);
24306
+ if (((_event$data = event.data) === null || _event$data === void 0 ? void 0 : _event$data.type) === 'SET_CHANNEL_ID' && typeof event.data.channelId === 'string') {
24307
+ var newChannelId = event.data.channelId;
24308
+ window.octostarChannelId = newChannelId;
24309
+ console.log('PostRobot: received channelId', newChannelId);
24310
+ // Clear cached resolvedMode if channel ID changed and we're in iframe mode
24311
+ // This ensures createRemoteApiHandle re-resolves with the new channel ID
24312
+ var manager = getOctostarConnectionManager();
24313
+ manager.clearResolvedModeIfChannelChanged(newChannelId);
23893
24314
  }
23894
24315
  });
24316
+ /**
24317
+ * Creates a remote API handle. This is a convenience function that delegates to the manager.
24318
+ * @deprecated Use getOctostarConnectionManager().createRemoteApiHandle() instead
24319
+ */
23895
24320
  var createRemoteApiHandle = exports.createRemoteApiHandle = /*#__PURE__*/function () {
23896
- var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(params) {
23897
- var channelId, octostarWindow, topic, response, api, _t;
23898
- return _regenerator().w(function (_context) {
23899
- while (1) switch (_context.p = _context.n) {
24321
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(params) {
24322
+ return _regenerator().w(function (_context2) {
24323
+ while (1) switch (_context2.n) {
23900
24324
  case 0:
23901
- channelId = traverseForChannelId();
23902
- if (channelId) {
23903
- _context.n = 1;
23904
- break;
23905
- }
23906
- throw new Error('PostRobot: No channelId found');
23907
- case 1:
23908
- octostarWindow = getOctostarWindow(channelId);
23909
- console.log("PostRobot: Trying to get handle ".concat(channelId));
23910
- topic = (0, _constants.getPostMessageNames)(channelId).get_api;
23911
- _context.p = 2;
23912
- _context.n = 3;
23913
- return (0, _utils.retry)(function () {
23914
- return postRobot.send(octostarWindow, topic, params);
23915
- }, {
23916
- maxAttempts: 5,
23917
- retryInterval: 2000
23918
- });
23919
- case 3:
23920
- response = _context.v;
23921
- console.log("PostRobot: Got remote api handle for ".concat(params.name, " on ").concat(channelId));
23922
- api = handlePostResponse(response);
23923
- return _context.a(2, createObjectProxy(api, {
23924
- name: params.name
23925
- }));
23926
- case 4:
23927
- _context.p = 4;
23928
- _t = _context.v;
23929
- console.log("PostRobot: Error while trying to create remote API handle on ".concat(topic), _t);
23930
- throw _t;
23931
- case 5:
23932
- return _context.a(2);
24325
+ return _context2.a(2, getOctostarConnectionManager().createRemoteApiHandle(params));
23933
24326
  }
23934
- }, _callee, null, [[2, 4]]);
24327
+ }, _callee2);
23935
24328
  }));
23936
- return function createRemoteApiHandle(_x) {
24329
+ return function createRemoteApiHandle(_x2) {
23937
24330
  return _ref.apply(this, arguments);
23938
24331
  };
23939
24332
  }();
24333
+ /**
24334
+ * Forwards calls to a future object. Used for creating proxies that forward to promises.
24335
+ */
23940
24336
  var forwardCallsToFutureObject = exports.forwardCallsToFutureObject = function forwardCallsToFutureObject(chain) {
23941
24337
  return new Proxy({}, {
23942
- get: function get(target, prop) {
24338
+ get: function get(_, prop) {
23943
24339
  return new Proxy(function () {}, {
23944
- apply: function apply(__, _, args) {
24340
+ apply: function apply(_, __, args) {
23945
24341
  return chain.then(function (obj) {
23946
24342
  return obj[prop].apply(obj, _toConsumableArray(args));
23947
24343
  });
@@ -23951,7 +24347,7 @@ var forwardCallsToFutureObject = exports.forwardCallsToFutureObject = function f
23951
24347
  });
23952
24348
  };
23953
24349
 
23954
- },{"./constants":34,"./utils":52,"post-robot":6}],36:[function(require,module,exports){
24350
+ },{"./constants":34,"./utils":53,"post-robot":6}],36:[function(require,module,exports){
23955
24351
  "use strict";
23956
24352
 
23957
24353
  Object.defineProperty(exports, "__esModule", {
@@ -24155,8 +24551,19 @@ Object.keys(_ApiConfig).forEach(function (key) {
24155
24551
  }
24156
24552
  });
24157
24553
  });
24554
+ var _RemoteDevManager = require("./lib/RemoteDevManager");
24555
+ Object.keys(_RemoteDevManager).forEach(function (key) {
24556
+ if (key === "default" || key === "__esModule") return;
24557
+ if (key in exports && exports[key] === _RemoteDevManager[key]) return;
24558
+ Object.defineProperty(exports, key, {
24559
+ enumerable: true,
24560
+ get: function get() {
24561
+ return _RemoteDevManager[key];
24562
+ }
24563
+ });
24564
+ });
24158
24565
 
24159
- },{"./apis":23,"./components":33,"./constants":34,"./lib/AIClientImpl":37,"./lib/ApiConfig":38,"./lib/ContextApiRegistry":40,"./lib/FilesAPIImpl":41,"./lib/FusionApi":42,"./lib/JWTProvider":43,"./lib/LiveContextAPI":44,"./lib/Proxy":45,"./lib/SearchQueryBuilder":46,"./lib/browserChannel":47,"./lib/userWorkspace":48,"./permissions":49,"./type/FusionTypes":50,"./types":51,"./utils":52}],37:[function(require,module,exports){
24566
+ },{"./apis":23,"./components":33,"./constants":34,"./lib/AIClientImpl":37,"./lib/ApiConfig":38,"./lib/ContextApiRegistry":40,"./lib/FilesAPIImpl":41,"./lib/FusionApi":42,"./lib/JWTProvider":43,"./lib/LiveContextAPI":44,"./lib/Proxy":45,"./lib/RemoteDevManager":46,"./lib/SearchQueryBuilder":47,"./lib/browserChannel":48,"./lib/userWorkspace":49,"./permissions":50,"./type/FusionTypes":51,"./types":52,"./utils":53}],37:[function(require,module,exports){
24160
24567
  "use strict";
24161
24568
 
24162
24569
  Object.defineProperty(exports, "__esModule", {
@@ -24983,7 +25390,7 @@ var FilesAPIImpl = exports.FilesAPIImpl = /*#__PURE__*/function () {
24983
25390
  }]);
24984
25391
  }();
24985
25392
 
24986
- },{"./browserChannel":47}],42:[function(require,module,exports){
25393
+ },{"./browserChannel":48}],42:[function(require,module,exports){
24987
25394
  "use strict";
24988
25395
 
24989
25396
  Object.defineProperty(exports, "__esModule", {
@@ -26210,6 +26617,260 @@ var makeProxy = exports.makeProxy = function makeProxy(obj) {
26210
26617
  },{}],46:[function(require,module,exports){
26211
26618
  "use strict";
26212
26619
 
26620
+ Object.defineProperty(exports, "__esModule", {
26621
+ value: true
26622
+ });
26623
+ exports.RemoteDevManager = void 0;
26624
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
26625
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
26626
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
26627
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
26628
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
26629
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
26630
+ /**
26631
+ * Singleton manager for remote dev channel ID and app entity mapping.
26632
+ * Maintains state in memory and persists to localStorage.
26633
+ * Automatically initializes from URL parameter and localStorage on first access.
26634
+ */
26635
+ var STORAGE_PREFIX = 'octostarRemoteDevMapping-';
26636
+ /**
26637
+ * Singleton manager for remote dev channel ID and app entity mapping.
26638
+ * Only one remote dev app can be active at a time.
26639
+ */
26640
+ var RemoteDevManager = exports.RemoteDevManager = /*#__PURE__*/function () {
26641
+ function RemoteDevManager() {
26642
+ _classCallCheck(this, RemoteDevManager);
26643
+ this.remoteDevChannelId = null;
26644
+ this.appEntity = null;
26645
+ this.listeners = new Set();
26646
+ this.initialized = false;
26647
+ // Private constructor for singleton pattern
26648
+ }
26649
+ /**
26650
+ * Get the singleton instance. Automatically initializes on first call.
26651
+ */
26652
+ return _createClass(RemoteDevManager, [{
26653
+ key: "getRemoteDevChannelId",
26654
+ value:
26655
+ /**
26656
+ * Get the current remote dev channel ID.
26657
+ */
26658
+ function getRemoteDevChannelId() {
26659
+ return this.remoteDevChannelId;
26660
+ }
26661
+ /**
26662
+ * Check if the current app is running in remote dev mode.
26663
+ */
26664
+ }, {
26665
+ key: "isRemoteDevMode",
26666
+ value: function isRemoteDevMode() {
26667
+ return this.remoteDevChannelId !== null;
26668
+ }
26669
+ /**
26670
+ * Get the current app entity ID (entity_id from appEntity).
26671
+ */
26672
+ }, {
26673
+ key: "getAppId",
26674
+ value: function getAppId() {
26675
+ var _this$appEntity$entit, _this$appEntity;
26676
+ return (_this$appEntity$entit = (_this$appEntity = this.appEntity) === null || _this$appEntity === void 0 ? void 0 : _this$appEntity.entity_id) !== null && _this$appEntity$entit !== void 0 ? _this$appEntity$entit : null;
26677
+ }
26678
+ /**
26679
+ * Get the current app entity.
26680
+ */
26681
+ }, {
26682
+ key: "getAppEntity",
26683
+ value: function getAppEntity() {
26684
+ return this.appEntity;
26685
+ }
26686
+ /**
26687
+ * Set the mapping between remote dev channel ID and app entity.
26688
+ * Saves to localStorage and notifies all listeners.
26689
+ */
26690
+ }, {
26691
+ key: "setMapping",
26692
+ value: function setMapping(remoteDevChannelId, entity) {
26693
+ if (!remoteDevChannelId || !entity || !entity.entity_id || !entity.entity_type || !entity.entity_label) {
26694
+ return;
26695
+ }
26696
+ // Check localStorage accessibility
26697
+ if (!this.isLocalStorageAvailable()) {
26698
+ return;
26699
+ }
26700
+ var key = "".concat(STORAGE_PREFIX).concat(remoteDevChannelId);
26701
+ // Store the minimal entity object with just the required fields
26702
+ var entityToStore = {
26703
+ entity_type: entity.entity_type,
26704
+ entity_id: entity.entity_id,
26705
+ entity_label: entity.entity_label
26706
+ };
26707
+ var valueToStore = JSON.stringify(entityToStore);
26708
+ try {
26709
+ localStorage.setItem(key, valueToStore);
26710
+ this.remoteDevChannelId = remoteDevChannelId;
26711
+ this.appEntity = entityToStore;
26712
+ this.notifyListeners();
26713
+ } catch (error) {
26714
+ // Silently fail if storage is unavailable
26715
+ }
26716
+ }
26717
+ /**
26718
+ * Clear the current mapping.
26719
+ * Removes from localStorage and notifies all listeners.
26720
+ */
26721
+ }, {
26722
+ key: "clear",
26723
+ value: function clear() {
26724
+ if (this.remoteDevChannelId) {
26725
+ var key = "".concat(STORAGE_PREFIX).concat(this.remoteDevChannelId);
26726
+ try {
26727
+ localStorage.removeItem(key);
26728
+ } catch (error) {
26729
+ // Silently fail if storage is unavailable
26730
+ }
26731
+ }
26732
+ this.remoteDevChannelId = null;
26733
+ this.appEntity = null;
26734
+ this.notifyListeners();
26735
+ }
26736
+ /**
26737
+ * Subscribe to state changes.
26738
+ * Returns an unsubscribe function.
26739
+ */
26740
+ }, {
26741
+ key: "subscribe",
26742
+ value: function subscribe(listener) {
26743
+ var _this = this;
26744
+ this.listeners.add(listener);
26745
+ return function () {
26746
+ _this.listeners["delete"](listener);
26747
+ };
26748
+ }
26749
+ /**
26750
+ * Private: Initialize from URL parameter and localStorage.
26751
+ * Called automatically on first getInstance() call.
26752
+ */
26753
+ }, {
26754
+ key: "initialize",
26755
+ value: function initialize() {
26756
+ if (this.initialized) {
26757
+ return;
26758
+ }
26759
+ this.initialized = true;
26760
+ // Get remoteDevChannelId from URL
26761
+ var urlChannelId = this.getRemoteDevChannelIdFromUrl();
26762
+ if (urlChannelId) {
26763
+ // Clear URL parameter immediately
26764
+ this.removeRemoteDevChannelIdFromUrl();
26765
+ // Always set remoteDevChannelId when present in URL (so modal can show for unrecognised IDs)
26766
+ this.remoteDevChannelId = urlChannelId;
26767
+ // Load entity from localStorage if we have a cached mapping
26768
+ this.appEntity = this.getAppEntityForChannel(urlChannelId);
26769
+ }
26770
+ }
26771
+ /**
26772
+ * Private: Get remote dev channel ID from URL search parameters.
26773
+ */
26774
+ }, {
26775
+ key: "getRemoteDevChannelIdFromUrl",
26776
+ value: function getRemoteDevChannelIdFromUrl() {
26777
+ if (typeof window === 'undefined') return null;
26778
+ try {
26779
+ var params = new URLSearchParams(window.location.search);
26780
+ return params.get('remoteDevChannelId');
26781
+ } catch (_unused) {
26782
+ return null;
26783
+ }
26784
+ }
26785
+ /**
26786
+ * Private: Remove remoteDevChannelId from URL search parameters.
26787
+ */
26788
+ }, {
26789
+ key: "removeRemoteDevChannelIdFromUrl",
26790
+ value: function removeRemoteDevChannelIdFromUrl() {
26791
+ if (typeof window === 'undefined') return;
26792
+ try {
26793
+ var params = new URLSearchParams(window.location.search);
26794
+ params["delete"]('remoteDevChannelId');
26795
+ var newUrl = window.location.pathname + (params.toString() ? "?".concat(params.toString()) : '') + window.location.hash;
26796
+ window.history.replaceState({}, '', newUrl);
26797
+ } catch (_unused2) {
26798
+ // Silently fail if URL manipulation fails
26799
+ }
26800
+ }
26801
+ /**
26802
+ * Private: Get app entity from localStorage for a given channel ID.
26803
+ */
26804
+ }, {
26805
+ key: "getAppEntityForChannel",
26806
+ value: function getAppEntityForChannel(channelId) {
26807
+ if (!channelId) return null;
26808
+ if (!this.isLocalStorageAvailable()) {
26809
+ return null;
26810
+ }
26811
+ var key = "".concat(STORAGE_PREFIX).concat(channelId);
26812
+ var stored = localStorage.getItem(key);
26813
+ if (!stored) {
26814
+ return null;
26815
+ }
26816
+ try {
26817
+ var entity = JSON.parse(stored);
26818
+ // Validate it has the required fields
26819
+ if (entity !== null && entity !== void 0 && entity.entity_type && entity.entity_id && entity.entity_label) {
26820
+ return entity;
26821
+ }
26822
+ console.error('Invalid remote dev mapping:', entity);
26823
+ } catch (error) {
26824
+ console.error('Failed to parse remote dev mapping:', error);
26825
+ }
26826
+ return null;
26827
+ }
26828
+ /**
26829
+ * Private: Check if localStorage is available.
26830
+ */
26831
+ }, {
26832
+ key: "isLocalStorageAvailable",
26833
+ value: function isLocalStorageAvailable() {
26834
+ try {
26835
+ var testKey = '__test_storage_access__';
26836
+ localStorage.setItem(testKey, 'test');
26837
+ localStorage.removeItem(testKey);
26838
+ return true;
26839
+ } catch (_unused3) {
26840
+ return false;
26841
+ }
26842
+ }
26843
+ /**
26844
+ * Private: Notify all listeners of state changes.
26845
+ */
26846
+ }, {
26847
+ key: "notifyListeners",
26848
+ value: function notifyListeners() {
26849
+ this.listeners.forEach(function (listener) {
26850
+ try {
26851
+ listener();
26852
+ } catch (error) {
26853
+ console.error('Error in RemoteDevManager listener:', error);
26854
+ }
26855
+ });
26856
+ }
26857
+ }], [{
26858
+ key: "getInstance",
26859
+ value: function getInstance() {
26860
+ if (!RemoteDevManager.instance) {
26861
+ RemoteDevManager.instance = new RemoteDevManager();
26862
+ }
26863
+ if (!RemoteDevManager.instance.initialized) {
26864
+ RemoteDevManager.instance.initialize();
26865
+ }
26866
+ return RemoteDevManager.instance;
26867
+ }
26868
+ }]);
26869
+ }();
26870
+
26871
+ },{}],47:[function(require,module,exports){
26872
+ "use strict";
26873
+
26213
26874
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
26214
26875
  Object.defineProperty(exports, "__esModule", {
26215
26876
  value: true
@@ -26315,7 +26976,7 @@ function buildTextSearchClauses(query, options) {
26315
26976
  return clauses;
26316
26977
  }
26317
26978
 
26318
- },{}],47:[function(require,module,exports){
26979
+ },{}],48:[function(require,module,exports){
26319
26980
  "use strict";
26320
26981
 
26321
26982
  Object.defineProperty(exports, "__esModule", {
@@ -26387,7 +27048,7 @@ function readBrowserChannel() {
26387
27048
  return getBrowserChannel();
26388
27049
  }
26389
27050
 
26390
- },{}],48:[function(require,module,exports){
27051
+ },{}],49:[function(require,module,exports){
26391
27052
  "use strict";
26392
27053
 
26393
27054
  Object.defineProperty(exports, "__esModule", {
@@ -26466,7 +27127,7 @@ var getOrCreateUsersPrivateWorkspaceRecord = exports.getOrCreateUsersPrivateWork
26466
27127
  };
26467
27128
  }();
26468
27129
 
26469
- },{"uuid":7}],49:[function(require,module,exports){
27130
+ },{"uuid":7}],50:[function(require,module,exports){
26470
27131
  "use strict";
26471
27132
 
26472
27133
  Object.defineProperty(exports, "__esModule", {
@@ -26491,21 +27152,21 @@ var ONTOLOGY_PERMISSION_GROUP = exports.ONTOLOGY_PERMISSION_GROUP = 'octostar:on
26491
27152
  var ALL_PERMISSIONS = exports.ALL_PERMISSIONS = 'all';
26492
27153
  var ALL_PERMISSIONS_ARRAY = exports.ALL_PERMISSIONS_ARRAY = [ALL_PERMISSIONS];
26493
27154
 
26494
- },{}],50:[function(require,module,exports){
27155
+ },{}],51:[function(require,module,exports){
26495
27156
  "use strict";
26496
27157
 
26497
27158
  Object.defineProperty(exports, "__esModule", {
26498
27159
  value: true
26499
27160
  });
26500
27161
 
26501
- },{}],51:[function(require,module,exports){
27162
+ },{}],52:[function(require,module,exports){
26502
27163
  "use strict";
26503
27164
 
26504
27165
  Object.defineProperty(exports, "__esModule", {
26505
27166
  value: true
26506
27167
  });
26507
27168
 
26508
- },{}],52:[function(require,module,exports){
27169
+ },{}],53:[function(require,module,exports){
26509
27170
  "use strict";
26510
27171
 
26511
27172
  Object.defineProperty(exports, "__esModule", {
@@ -26536,7 +27197,7 @@ var retry = exports.retry = /*#__PURE__*/function () {
26536
27197
  retryInterval = (_options$retryInterva = options === null || options === void 0 ? void 0 : options.retryInterval) !== null && _options$retryInterva !== void 0 ? _options$retryInterva : 1000;
26537
27198
  case 1:
26538
27199
  if (!true) {
26539
- _context.n = 6;
27200
+ _context.n = 7;
26540
27201
  break;
26541
27202
  }
26542
27203
  attempts += 1;
@@ -26548,17 +27209,20 @@ var retry = exports.retry = /*#__PURE__*/function () {
26548
27209
  case 4:
26549
27210
  _context.p = 4;
26550
27211
  _t = _context.v;
26551
- if (!(attempts < maxAttempts)) {
27212
+ if (!(attempts >= maxAttempts)) {
26552
27213
  _context.n = 5;
26553
27214
  break;
26554
27215
  }
26555
- _context.n = 5;
27216
+ throw _t;
27217
+ case 5:
27218
+ _context.n = 6;
26556
27219
  return new Promise(function (resolve) {
26557
27220
  return setTimeout(resolve, retryInterval);
26558
27221
  });
26559
- case 5:
26560
- throw _t;
26561
27222
  case 6:
27223
+ _context.n = 1;
27224
+ break;
27225
+ case 7:
26562
27226
  return _context.a(2);
26563
27227
  }
26564
27228
  }, _callee, null, [[2, 4]]);