roboto-js 1.9.5 → 1.9.7
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/.last-build +1 -1
- package/README.md +580 -0
- package/dist/cjs/cookie_storage_adaptor.cjs +22 -7
- package/dist/cjs/index.cjs +137 -82
- package/dist/cjs/rbt_api.cjs +529 -298
- package/dist/cjs/version.cjs +2 -2
- package/dist/cookie_storage_adaptor.js +12 -26
- package/dist/esm/cookie_storage_adaptor.js +22 -7
- package/dist/esm/index.js +137 -82
- package/dist/esm/rbt_api.js +529 -298
- package/dist/esm/version.js +2 -2
- package/dist/index.js +118 -3
- package/dist/version.js +2 -2
- package/package.json +1 -1
- package/src/cookie_storage_adaptor.js +14 -15
- package/src/index.js +16 -0
- package/src/rbt_api.js +164 -0
- package/src/version.js +2 -2
package/dist/cjs/rbt_api.cjs
CHANGED
|
@@ -14,12 +14,12 @@ var _idb = require("idb");
|
|
|
14
14
|
var _excluded = ["enableRealtime"],
|
|
15
15
|
_excluded2 = ["enableRealtime"];
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
17
|
-
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); }
|
|
18
17
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
19
18
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
20
19
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
21
20
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
22
21
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
22
|
+
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); }
|
|
23
23
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
24
24
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
25
25
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -95,6 +95,8 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
95
95
|
this.requestCache = {};
|
|
96
96
|
this._loadCurrentUserPromise = null;
|
|
97
97
|
this._loadCurrentUserExtendedPromise = null;
|
|
98
|
+
this.currentOrganization = null;
|
|
99
|
+
this._loadCurrentOrgPromise = null;
|
|
98
100
|
|
|
99
101
|
// Use the storageAdaptor to get the authToken, if available
|
|
100
102
|
this.initAuthToken(authtoken);
|
|
@@ -500,16 +502,23 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
500
502
|
_context6.next = 16;
|
|
501
503
|
return this.localStorageAdaptor.setItem('rbtUser', JSON.stringify(this.iac_session.user));
|
|
502
504
|
case 16:
|
|
505
|
+
// Optionally load organization after login (can be disabled with loadOrganization: false)
|
|
506
|
+
if (params.loadOrganization !== false) {
|
|
507
|
+
// Kick off org load asynchronously but don't wait for it
|
|
508
|
+
this.loadCurrentOrganization()["catch"](function (err) {
|
|
509
|
+
return void 0;
|
|
510
|
+
});
|
|
511
|
+
}
|
|
503
512
|
return _context6.abrupt("return", response.data);
|
|
504
|
-
case
|
|
505
|
-
_context6.prev =
|
|
513
|
+
case 20:
|
|
514
|
+
_context6.prev = 20;
|
|
506
515
|
_context6.t0 = _context6["catch"](0);
|
|
507
516
|
this._handleError(_context6.t0);
|
|
508
|
-
case
|
|
517
|
+
case 23:
|
|
509
518
|
case "end":
|
|
510
519
|
return _context6.stop();
|
|
511
520
|
}
|
|
512
|
-
}, _callee6, this, [[0,
|
|
521
|
+
}, _callee6, this, [[0, 20]]);
|
|
513
522
|
}));
|
|
514
523
|
function login(_x4) {
|
|
515
524
|
return _login.apply(this, arguments);
|
|
@@ -547,16 +556,20 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
547
556
|
_context7.next = 13;
|
|
548
557
|
return this.localStorageAdaptor.setItem('authtoken', response.authToken);
|
|
549
558
|
case 13:
|
|
559
|
+
// Load organization after OAuth login
|
|
560
|
+
this.loadCurrentOrganization()["catch"](function (err) {
|
|
561
|
+
return void 0;
|
|
562
|
+
});
|
|
550
563
|
return _context7.abrupt("return", response);
|
|
551
|
-
case
|
|
552
|
-
_context7.prev =
|
|
564
|
+
case 17:
|
|
565
|
+
_context7.prev = 17;
|
|
553
566
|
_context7.t0 = _context7["catch"](0);
|
|
554
567
|
this._handleError(_context7.t0);
|
|
555
|
-
case
|
|
568
|
+
case 20:
|
|
556
569
|
case "end":
|
|
557
570
|
return _context7.stop();
|
|
558
571
|
}
|
|
559
|
-
}, _callee7, this, [[0,
|
|
572
|
+
}, _callee7, this, [[0, 17]]);
|
|
560
573
|
}));
|
|
561
574
|
function loginWithOauth(_x5) {
|
|
562
575
|
return _loginWithOauth.apply(this, arguments);
|
|
@@ -585,6 +598,7 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
585
598
|
// Clear the iac_session and remove the auth token from axios headers
|
|
586
599
|
this.iac_session = null;
|
|
587
600
|
this.currentUser = null;
|
|
601
|
+
this.currentOrganization = null;
|
|
588
602
|
this.authtoken = null;
|
|
589
603
|
if (this.axios.defaults.headers.common['authtoken']) {
|
|
590
604
|
delete this.axios.defaults.headers.common['authtoken'];
|
|
@@ -592,22 +606,28 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
592
606
|
|
|
593
607
|
// Clear localStorage if it's being used
|
|
594
608
|
if (!this.localStorageAdaptor) {
|
|
595
|
-
_context8.next =
|
|
609
|
+
_context8.next = 18;
|
|
596
610
|
break;
|
|
597
611
|
}
|
|
598
|
-
_context8.next =
|
|
612
|
+
_context8.next = 14;
|
|
599
613
|
return this.localStorageAdaptor.removeItem('authtoken');
|
|
600
|
-
case
|
|
601
|
-
|
|
614
|
+
case 14:
|
|
615
|
+
_context8.next = 16;
|
|
616
|
+
return this.localStorageAdaptor.removeItem('rbtUser');
|
|
602
617
|
case 16:
|
|
603
|
-
_context8.
|
|
618
|
+
_context8.next = 18;
|
|
619
|
+
return this.localStorageAdaptor.removeItem('currentOrgId');
|
|
620
|
+
case 18:
|
|
621
|
+
return _context8.abrupt("return", response.data);
|
|
622
|
+
case 21:
|
|
623
|
+
_context8.prev = 21;
|
|
604
624
|
_context8.t0 = _context8["catch"](0);
|
|
605
625
|
this._handleError(_context8.t0);
|
|
606
|
-
case
|
|
626
|
+
case 24:
|
|
607
627
|
case "end":
|
|
608
628
|
return _context8.stop();
|
|
609
629
|
}
|
|
610
|
-
}, _callee8, this, [[0,
|
|
630
|
+
}, _callee8, this, [[0, 21]]);
|
|
611
631
|
}));
|
|
612
632
|
function logout() {
|
|
613
633
|
return _logout.apply(this, arguments);
|
|
@@ -809,14 +829,225 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
809
829
|
}
|
|
810
830
|
return loadCurrentUserExtended;
|
|
811
831
|
}()
|
|
832
|
+
/**
|
|
833
|
+
* Load current organization for the authenticated user
|
|
834
|
+
* Organization is determined by:
|
|
835
|
+
* 1. User's mod.currentOrgId preference
|
|
836
|
+
* 2. First organization in user.organizations array
|
|
837
|
+
* 3. null if user has no organizations
|
|
838
|
+
*
|
|
839
|
+
* @param {boolean} forceReload - Force reload from server even if cached
|
|
840
|
+
* @returns {Promise<RbtObject|null>} Organization object or null
|
|
841
|
+
*/
|
|
812
842
|
}, {
|
|
813
|
-
key: "
|
|
814
|
-
value: function () {
|
|
815
|
-
var
|
|
843
|
+
key: "loadCurrentOrganization",
|
|
844
|
+
value: (function () {
|
|
845
|
+
var _loadCurrentOrganization = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
|
|
816
846
|
var _this4 = this;
|
|
817
|
-
var
|
|
847
|
+
var forceReload,
|
|
848
|
+
result,
|
|
849
|
+
_args15 = arguments;
|
|
818
850
|
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
819
851
|
while (1) switch (_context15.prev = _context15.next) {
|
|
852
|
+
case 0:
|
|
853
|
+
forceReload = _args15.length > 0 && _args15[0] !== undefined ? _args15[0] : false;
|
|
854
|
+
_context15.prev = 1;
|
|
855
|
+
if (!(this.currentOrganization && !forceReload)) {
|
|
856
|
+
_context15.next = 4;
|
|
857
|
+
break;
|
|
858
|
+
}
|
|
859
|
+
return _context15.abrupt("return", this.currentOrganization);
|
|
860
|
+
case 4:
|
|
861
|
+
if (!this._loadCurrentOrgPromise) {
|
|
862
|
+
_context15.next = 6;
|
|
863
|
+
break;
|
|
864
|
+
}
|
|
865
|
+
return _context15.abrupt("return", this._loadCurrentOrgPromise);
|
|
866
|
+
case 6:
|
|
867
|
+
this._loadCurrentOrgPromise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
|
|
868
|
+
var _userData$organizatio, _userData$mod, user, userData, firstOrg, orgId, cachedOrgId, org;
|
|
869
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
870
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
871
|
+
case 0:
|
|
872
|
+
_context14.prev = 0;
|
|
873
|
+
_context14.next = 3;
|
|
874
|
+
return _this4.loadCurrentUser();
|
|
875
|
+
case 3:
|
|
876
|
+
user = _context14.sent;
|
|
877
|
+
if (user) {
|
|
878
|
+
_context14.next = 6;
|
|
879
|
+
break;
|
|
880
|
+
}
|
|
881
|
+
return _context14.abrupt("return", null);
|
|
882
|
+
case 6:
|
|
883
|
+
// Get organization ID from user preferences or first org
|
|
884
|
+
userData = user.getData(); // organizations array format: [{ id: 'org123', roles: ['owner'] }, ...]
|
|
885
|
+
firstOrg = (_userData$organizatio = userData.organizations) === null || _userData$organizatio === void 0 ? void 0 : _userData$organizatio[0];
|
|
886
|
+
orgId = ((_userData$mod = userData.mod) === null || _userData$mod === void 0 ? void 0 : _userData$mod.currentOrgId) || (_typeof(firstOrg) === 'object' ? firstOrg === null || firstOrg === void 0 ? void 0 : firstOrg.id : firstOrg);
|
|
887
|
+
if (orgId) {
|
|
888
|
+
_context14.next = 11;
|
|
889
|
+
break;
|
|
890
|
+
}
|
|
891
|
+
return _context14.abrupt("return", null);
|
|
892
|
+
case 11:
|
|
893
|
+
if (!_this4.localStorageAdaptor) {
|
|
894
|
+
_context14.next = 16;
|
|
895
|
+
break;
|
|
896
|
+
}
|
|
897
|
+
_context14.next = 14;
|
|
898
|
+
return _this4.localStorageAdaptor.getItem('currentOrgId');
|
|
899
|
+
case 14:
|
|
900
|
+
cachedOrgId = _context14.sent;
|
|
901
|
+
if (cachedOrgId && cachedOrgId !== orgId) {}
|
|
902
|
+
case 16:
|
|
903
|
+
_context14.next = 18;
|
|
904
|
+
return _this4.get('<@iac.organization>', orgId);
|
|
905
|
+
case 18:
|
|
906
|
+
org = _context14.sent;
|
|
907
|
+
if (!org) {
|
|
908
|
+
_context14.next = 26;
|
|
909
|
+
break;
|
|
910
|
+
}
|
|
911
|
+
_this4.currentOrganization = org; // Already an RbtObject
|
|
912
|
+
if (!_this4.localStorageAdaptor) {
|
|
913
|
+
_context14.next = 24;
|
|
914
|
+
break;
|
|
915
|
+
}
|
|
916
|
+
_context14.next = 24;
|
|
917
|
+
return _this4.localStorageAdaptor.setItem('currentOrgId', orgId);
|
|
918
|
+
case 24:
|
|
919
|
+
_context14.next = 26;
|
|
920
|
+
break;
|
|
921
|
+
case 26:
|
|
922
|
+
return _context14.abrupt("return", _this4.currentOrganization);
|
|
923
|
+
case 29:
|
|
924
|
+
_context14.prev = 29;
|
|
925
|
+
_context14.t0 = _context14["catch"](0);
|
|
926
|
+
console.error('[RbtApi] Failed to load current organization:', _context14.t0);
|
|
927
|
+
_this4.currentOrganization = null;
|
|
928
|
+
return _context14.abrupt("return", null);
|
|
929
|
+
case 34:
|
|
930
|
+
case "end":
|
|
931
|
+
return _context14.stop();
|
|
932
|
+
}
|
|
933
|
+
}, _callee14, null, [[0, 29]]);
|
|
934
|
+
}))();
|
|
935
|
+
_context15.next = 9;
|
|
936
|
+
return this._loadCurrentOrgPromise;
|
|
937
|
+
case 9:
|
|
938
|
+
result = _context15.sent;
|
|
939
|
+
this._loadCurrentOrgPromise = null;
|
|
940
|
+
return _context15.abrupt("return", result);
|
|
941
|
+
case 14:
|
|
942
|
+
_context15.prev = 14;
|
|
943
|
+
_context15.t0 = _context15["catch"](1);
|
|
944
|
+
this._loadCurrentOrgPromise = null;
|
|
945
|
+
return _context15.abrupt("return", this._handleError(_context15.t0));
|
|
946
|
+
case 18:
|
|
947
|
+
case "end":
|
|
948
|
+
return _context15.stop();
|
|
949
|
+
}
|
|
950
|
+
}, _callee15, this, [[1, 14]]);
|
|
951
|
+
}));
|
|
952
|
+
function loadCurrentOrganization() {
|
|
953
|
+
return _loadCurrentOrganization.apply(this, arguments);
|
|
954
|
+
}
|
|
955
|
+
return loadCurrentOrganization;
|
|
956
|
+
}()
|
|
957
|
+
/**
|
|
958
|
+
* Switch to a different organization
|
|
959
|
+
* Updates user preference and loads the new organization
|
|
960
|
+
*
|
|
961
|
+
* @param {string} orgId - Organization ID to switch to
|
|
962
|
+
* @returns {Promise<RbtObject>} The new current organization
|
|
963
|
+
*/
|
|
964
|
+
)
|
|
965
|
+
}, {
|
|
966
|
+
key: "switchOrganization",
|
|
967
|
+
value: (function () {
|
|
968
|
+
var _switchOrganization = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(orgId) {
|
|
969
|
+
var org, userObj;
|
|
970
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
971
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
972
|
+
case 0:
|
|
973
|
+
_context16.prev = 0;
|
|
974
|
+
if (this.currentUser) {
|
|
975
|
+
_context16.next = 3;
|
|
976
|
+
break;
|
|
977
|
+
}
|
|
978
|
+
throw new Error('Must be logged in to switch organization');
|
|
979
|
+
case 3:
|
|
980
|
+
_context16.next = 5;
|
|
981
|
+
return this.get('<@iac.organization>', orgId);
|
|
982
|
+
case 5:
|
|
983
|
+
org = _context16.sent;
|
|
984
|
+
if (org) {
|
|
985
|
+
_context16.next = 8;
|
|
986
|
+
break;
|
|
987
|
+
}
|
|
988
|
+
throw new Error("Organization ".concat(orgId, " not found or not accessible"));
|
|
989
|
+
case 8:
|
|
990
|
+
this.currentOrganization = org;
|
|
991
|
+
|
|
992
|
+
// Save preference to user
|
|
993
|
+
_context16.prev = 9;
|
|
994
|
+
_context16.next = 12;
|
|
995
|
+
return this.loadUser(this.currentUser.id);
|
|
996
|
+
case 12:
|
|
997
|
+
userObj = _context16.sent;
|
|
998
|
+
userObj.set('mod.currentOrgId', orgId);
|
|
999
|
+
_context16.next = 16;
|
|
1000
|
+
return userObj.save();
|
|
1001
|
+
case 16:
|
|
1002
|
+
if (!this.localStorageAdaptor) {
|
|
1003
|
+
_context16.next = 19;
|
|
1004
|
+
break;
|
|
1005
|
+
}
|
|
1006
|
+
_context16.next = 19;
|
|
1007
|
+
return this.localStorageAdaptor.setItem('currentOrgId', orgId);
|
|
1008
|
+
case 19:
|
|
1009
|
+
_context16.next = 23;
|
|
1010
|
+
break;
|
|
1011
|
+
case 21:
|
|
1012
|
+
_context16.prev = 21;
|
|
1013
|
+
_context16.t0 = _context16["catch"](9);
|
|
1014
|
+
case 23:
|
|
1015
|
+
return _context16.abrupt("return", org);
|
|
1016
|
+
case 26:
|
|
1017
|
+
_context16.prev = 26;
|
|
1018
|
+
_context16.t1 = _context16["catch"](0);
|
|
1019
|
+
return _context16.abrupt("return", this._handleError(_context16.t1));
|
|
1020
|
+
case 29:
|
|
1021
|
+
case "end":
|
|
1022
|
+
return _context16.stop();
|
|
1023
|
+
}
|
|
1024
|
+
}, _callee16, this, [[0, 26], [9, 21]]);
|
|
1025
|
+
}));
|
|
1026
|
+
function switchOrganization(_x7) {
|
|
1027
|
+
return _switchOrganization.apply(this, arguments);
|
|
1028
|
+
}
|
|
1029
|
+
return switchOrganization;
|
|
1030
|
+
}()
|
|
1031
|
+
/**
|
|
1032
|
+
* Get current organization (null-safe)
|
|
1033
|
+
* Returns cached organization without triggering a load
|
|
1034
|
+
*
|
|
1035
|
+
* @returns {RbtObject|null} Current organization or null
|
|
1036
|
+
*/
|
|
1037
|
+
)
|
|
1038
|
+
}, {
|
|
1039
|
+
key: "getCurrentOrganization",
|
|
1040
|
+
value: function getCurrentOrganization() {
|
|
1041
|
+
return this.currentOrganization;
|
|
1042
|
+
}
|
|
1043
|
+
}, {
|
|
1044
|
+
key: "loadUser",
|
|
1045
|
+
value: function () {
|
|
1046
|
+
var _loadUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(userId) {
|
|
1047
|
+
var _this5 = this;
|
|
1048
|
+
var params, cacheKey, now, existing, p;
|
|
1049
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
1050
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
820
1051
|
case 0:
|
|
821
1052
|
params = {
|
|
822
1053
|
id: userId
|
|
@@ -825,53 +1056,53 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
825
1056
|
now = Date.now();
|
|
826
1057
|
existing = this.requestCache[cacheKey];
|
|
827
1058
|
if (!(existing && now - existing.time < 10000)) {
|
|
828
|
-
|
|
1059
|
+
_context18.next = 6;
|
|
829
1060
|
break;
|
|
830
1061
|
}
|
|
831
|
-
return
|
|
1062
|
+
return _context18.abrupt("return", existing.val);
|
|
832
1063
|
case 6:
|
|
833
|
-
|
|
834
|
-
p = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1064
|
+
_context18.prev = 6;
|
|
1065
|
+
p = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
|
|
835
1066
|
var _response$data;
|
|
836
1067
|
var response, userData, User;
|
|
837
|
-
return _regeneratorRuntime().wrap(function
|
|
838
|
-
while (1) switch (
|
|
1068
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
1069
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
839
1070
|
case 0:
|
|
840
|
-
|
|
841
|
-
return
|
|
1071
|
+
_context17.next = 2;
|
|
1072
|
+
return _this5.axios.post('/user_service/loadUser', [params]);
|
|
842
1073
|
case 2:
|
|
843
|
-
response =
|
|
1074
|
+
response = _context17.sent;
|
|
844
1075
|
userData = response === null || response === void 0 || (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.user;
|
|
845
1076
|
User = new _rbt_user["default"]({
|
|
846
1077
|
id: userData.id
|
|
847
|
-
},
|
|
1078
|
+
}, _this5.axios);
|
|
848
1079
|
User.setData(userData);
|
|
849
|
-
return
|
|
1080
|
+
return _context17.abrupt("return", User);
|
|
850
1081
|
case 7:
|
|
851
1082
|
case "end":
|
|
852
|
-
return
|
|
1083
|
+
return _context17.stop();
|
|
853
1084
|
}
|
|
854
|
-
},
|
|
1085
|
+
}, _callee17);
|
|
855
1086
|
}))();
|
|
856
1087
|
this.requestCache[cacheKey] = {
|
|
857
1088
|
val: p,
|
|
858
1089
|
time: now
|
|
859
1090
|
};
|
|
860
|
-
|
|
1091
|
+
_context18.next = 11;
|
|
861
1092
|
return p;
|
|
862
1093
|
case 11:
|
|
863
|
-
return
|
|
1094
|
+
return _context18.abrupt("return", _context18.sent);
|
|
864
1095
|
case 14:
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
return
|
|
1096
|
+
_context18.prev = 14;
|
|
1097
|
+
_context18.t0 = _context18["catch"](6);
|
|
1098
|
+
return _context18.abrupt("return", this._handleError(_context18.t0));
|
|
868
1099
|
case 17:
|
|
869
1100
|
case "end":
|
|
870
|
-
return
|
|
1101
|
+
return _context18.stop();
|
|
871
1102
|
}
|
|
872
|
-
},
|
|
1103
|
+
}, _callee18, this, [[6, 14]]);
|
|
873
1104
|
}));
|
|
874
|
-
function loadUser(
|
|
1105
|
+
function loadUser(_x8) {
|
|
875
1106
|
return _loadUser.apply(this, arguments);
|
|
876
1107
|
}
|
|
877
1108
|
return loadUser;
|
|
@@ -879,53 +1110,53 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
879
1110
|
}, {
|
|
880
1111
|
key: "refreshAuthToken",
|
|
881
1112
|
value: function () {
|
|
882
|
-
var _refreshAuthToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1113
|
+
var _refreshAuthToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(authtoken) {
|
|
883
1114
|
var promise, response;
|
|
884
|
-
return _regeneratorRuntime().wrap(function
|
|
885
|
-
while (1) switch (
|
|
1115
|
+
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
1116
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
886
1117
|
case 0:
|
|
887
1118
|
if (this.appServiceHost) {
|
|
888
|
-
|
|
1119
|
+
_context19.next = 2;
|
|
889
1120
|
break;
|
|
890
1121
|
}
|
|
891
|
-
return
|
|
1122
|
+
return _context19.abrupt("return", false);
|
|
892
1123
|
case 2:
|
|
893
1124
|
if (!this.requestCache[authtoken]) {
|
|
894
|
-
|
|
1125
|
+
_context19.next = 4;
|
|
895
1126
|
break;
|
|
896
1127
|
}
|
|
897
|
-
return
|
|
1128
|
+
return _context19.abrupt("return", this.requestCache[authtoken]);
|
|
898
1129
|
case 4:
|
|
899
|
-
|
|
1130
|
+
_context19.prev = 4;
|
|
900
1131
|
//console.log('RBTTOK Req', authtoken);
|
|
901
1132
|
// Create a new promise for the token refresh and store it in the cache
|
|
902
1133
|
promise = this.axios.post('/user_service/refreshAuthToken', [authtoken]);
|
|
903
1134
|
this.requestCache[authtoken] = promise;
|
|
904
1135
|
|
|
905
1136
|
// Await the promise to get the response
|
|
906
|
-
|
|
1137
|
+
_context19.next = 9;
|
|
907
1138
|
return promise;
|
|
908
1139
|
case 9:
|
|
909
|
-
response =
|
|
1140
|
+
response = _context19.sent;
|
|
910
1141
|
//console.log('RBTTOK Response ',response);
|
|
911
1142
|
// Once the promise resolves, delete it from the cache to allow future refreshes
|
|
912
1143
|
delete this.requestCache[authtoken];
|
|
913
1144
|
|
|
914
1145
|
// Return the response data
|
|
915
|
-
return
|
|
1146
|
+
return _context19.abrupt("return", response.data);
|
|
916
1147
|
case 14:
|
|
917
|
-
|
|
918
|
-
|
|
1148
|
+
_context19.prev = 14;
|
|
1149
|
+
_context19.t0 = _context19["catch"](4);
|
|
919
1150
|
// On error, remove the cached promise to allow retries
|
|
920
1151
|
delete this.requestCache[authtoken];
|
|
921
|
-
this._handleError(
|
|
1152
|
+
this._handleError(_context19.t0);
|
|
922
1153
|
case 18:
|
|
923
1154
|
case "end":
|
|
924
|
-
return
|
|
1155
|
+
return _context19.stop();
|
|
925
1156
|
}
|
|
926
|
-
},
|
|
1157
|
+
}, _callee19, this, [[4, 14]]);
|
|
927
1158
|
}));
|
|
928
|
-
function refreshAuthToken(
|
|
1159
|
+
function refreshAuthToken(_x9) {
|
|
929
1160
|
return _refreshAuthToken.apply(this, arguments);
|
|
930
1161
|
}
|
|
931
1162
|
return refreshAuthToken;
|
|
@@ -956,31 +1187,31 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
956
1187
|
}, {
|
|
957
1188
|
key: "registerUser",
|
|
958
1189
|
value: function () {
|
|
959
|
-
var _registerUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1190
|
+
var _registerUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
|
|
960
1191
|
var dataHash,
|
|
961
1192
|
response,
|
|
962
1193
|
record,
|
|
963
|
-
|
|
964
|
-
return _regeneratorRuntime().wrap(function
|
|
965
|
-
while (1) switch (
|
|
1194
|
+
_args20 = arguments;
|
|
1195
|
+
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
1196
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
966
1197
|
case 0:
|
|
967
|
-
dataHash =
|
|
968
|
-
|
|
969
|
-
|
|
1198
|
+
dataHash = _args20.length > 0 && _args20[0] !== undefined ? _args20[0] : {};
|
|
1199
|
+
_context20.prev = 1;
|
|
1200
|
+
_context20.next = 4;
|
|
970
1201
|
return this.axios.post('/user_service/registerUser', [dataHash]);
|
|
971
1202
|
case 4:
|
|
972
|
-
response =
|
|
1203
|
+
response = _context20.sent;
|
|
973
1204
|
record = response.data;
|
|
974
|
-
return
|
|
1205
|
+
return _context20.abrupt("return", new _rbt_user["default"](record, this.axios));
|
|
975
1206
|
case 9:
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
return
|
|
1207
|
+
_context20.prev = 9;
|
|
1208
|
+
_context20.t0 = _context20["catch"](1);
|
|
1209
|
+
return _context20.abrupt("return", this._handleError(_context20.t0));
|
|
979
1210
|
case 12:
|
|
980
1211
|
case "end":
|
|
981
|
-
return
|
|
1212
|
+
return _context20.stop();
|
|
982
1213
|
}
|
|
983
|
-
},
|
|
1214
|
+
}, _callee20, this, [[1, 9]]);
|
|
984
1215
|
}));
|
|
985
1216
|
function registerUser() {
|
|
986
1217
|
return _registerUser.apply(this, arguments);
|
|
@@ -997,32 +1228,32 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
997
1228
|
}, {
|
|
998
1229
|
key: "createFile",
|
|
999
1230
|
value: (function () {
|
|
1000
|
-
var _createFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1231
|
+
var _createFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(dataHash) {
|
|
1001
1232
|
var response, record;
|
|
1002
|
-
return _regeneratorRuntime().wrap(function
|
|
1003
|
-
while (1) switch (
|
|
1233
|
+
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
1234
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
1004
1235
|
case 0:
|
|
1005
|
-
|
|
1006
|
-
|
|
1236
|
+
_context21.prev = 0;
|
|
1237
|
+
_context21.next = 3;
|
|
1007
1238
|
return this.axios.post('/object_service/createObject', ['<@filekit.file>', dataHash]);
|
|
1008
1239
|
case 3:
|
|
1009
|
-
response =
|
|
1240
|
+
response = _context21.sent;
|
|
1010
1241
|
record = response.data;
|
|
1011
1242
|
if (dataHash) {
|
|
1012
1243
|
record.data = dataHash;
|
|
1013
1244
|
}
|
|
1014
|
-
return
|
|
1245
|
+
return _context21.abrupt("return", new _rbt_file["default"](record, this.axios, this.localDb));
|
|
1015
1246
|
case 9:
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
return
|
|
1247
|
+
_context21.prev = 9;
|
|
1248
|
+
_context21.t0 = _context21["catch"](0);
|
|
1249
|
+
return _context21.abrupt("return", this._handleError(_context21.t0));
|
|
1019
1250
|
case 12:
|
|
1020
1251
|
case "end":
|
|
1021
|
-
return
|
|
1252
|
+
return _context21.stop();
|
|
1022
1253
|
}
|
|
1023
|
-
},
|
|
1254
|
+
}, _callee21, this, [[0, 9]]);
|
|
1024
1255
|
}));
|
|
1025
|
-
function createFile(
|
|
1256
|
+
function createFile(_x10) {
|
|
1026
1257
|
return _createFile.apply(this, arguments);
|
|
1027
1258
|
}
|
|
1028
1259
|
return createFile;
|
|
@@ -1030,35 +1261,35 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1030
1261
|
}, {
|
|
1031
1262
|
key: "loadFile",
|
|
1032
1263
|
value: function () {
|
|
1033
|
-
var _loadFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1264
|
+
var _loadFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(id) {
|
|
1034
1265
|
var response, record;
|
|
1035
|
-
return _regeneratorRuntime().wrap(function
|
|
1036
|
-
while (1) switch (
|
|
1266
|
+
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
1267
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
1037
1268
|
case 0:
|
|
1038
|
-
|
|
1039
|
-
|
|
1269
|
+
_context22.prev = 0;
|
|
1270
|
+
_context22.next = 3;
|
|
1040
1271
|
return this.load('<@filekit.file>', id);
|
|
1041
1272
|
case 3:
|
|
1042
|
-
response =
|
|
1273
|
+
response = _context22.sent;
|
|
1043
1274
|
if (response) {
|
|
1044
|
-
|
|
1275
|
+
_context22.next = 6;
|
|
1045
1276
|
break;
|
|
1046
1277
|
}
|
|
1047
|
-
return
|
|
1278
|
+
return _context22.abrupt("return", null);
|
|
1048
1279
|
case 6:
|
|
1049
1280
|
record = response.toRecord();
|
|
1050
|
-
return
|
|
1281
|
+
return _context22.abrupt("return", new _rbt_file["default"](record, this.axios, this.localDb));
|
|
1051
1282
|
case 10:
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
return
|
|
1283
|
+
_context22.prev = 10;
|
|
1284
|
+
_context22.t0 = _context22["catch"](0);
|
|
1285
|
+
return _context22.abrupt("return", this._handleError(_context22.t0));
|
|
1055
1286
|
case 13:
|
|
1056
1287
|
case "end":
|
|
1057
|
-
return
|
|
1288
|
+
return _context22.stop();
|
|
1058
1289
|
}
|
|
1059
|
-
},
|
|
1290
|
+
}, _callee22, this, [[0, 10]]);
|
|
1060
1291
|
}));
|
|
1061
|
-
function loadFile(
|
|
1292
|
+
function loadFile(_x11) {
|
|
1062
1293
|
return _loadFile.apply(this, arguments);
|
|
1063
1294
|
}
|
|
1064
1295
|
return loadFile;
|
|
@@ -1066,39 +1297,39 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1066
1297
|
}, {
|
|
1067
1298
|
key: "loadFiles",
|
|
1068
1299
|
value: function () {
|
|
1069
|
-
var _loadFiles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1070
|
-
var
|
|
1300
|
+
var _loadFiles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(ids) {
|
|
1301
|
+
var _this6 = this;
|
|
1071
1302
|
var responses;
|
|
1072
|
-
return _regeneratorRuntime().wrap(function
|
|
1073
|
-
while (1) switch (
|
|
1303
|
+
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
|
1304
|
+
while (1) switch (_context23.prev = _context23.next) {
|
|
1074
1305
|
case 0:
|
|
1075
|
-
|
|
1076
|
-
|
|
1306
|
+
_context23.prev = 0;
|
|
1307
|
+
_context23.next = 3;
|
|
1077
1308
|
return this.load('<@filekit.file>', ids);
|
|
1078
1309
|
case 3:
|
|
1079
|
-
responses =
|
|
1310
|
+
responses = _context23.sent;
|
|
1080
1311
|
if (!(!responses || !Array.isArray(responses))) {
|
|
1081
|
-
|
|
1312
|
+
_context23.next = 6;
|
|
1082
1313
|
break;
|
|
1083
1314
|
}
|
|
1084
|
-
return
|
|
1315
|
+
return _context23.abrupt("return", []);
|
|
1085
1316
|
case 6:
|
|
1086
|
-
return
|
|
1317
|
+
return _context23.abrupt("return", responses.map(function (response) {
|
|
1087
1318
|
var record = response.toRecord();
|
|
1088
|
-
return new _rbt_file["default"](record,
|
|
1319
|
+
return new _rbt_file["default"](record, _this6.axios, _this6.localDb);
|
|
1089
1320
|
}));
|
|
1090
1321
|
case 9:
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
this._handleError(
|
|
1094
|
-
return
|
|
1322
|
+
_context23.prev = 9;
|
|
1323
|
+
_context23.t0 = _context23["catch"](0);
|
|
1324
|
+
this._handleError(_context23.t0); // Handle errors (log or process as needed)
|
|
1325
|
+
return _context23.abrupt("return", []);
|
|
1095
1326
|
case 13:
|
|
1096
1327
|
case "end":
|
|
1097
|
-
return
|
|
1328
|
+
return _context23.stop();
|
|
1098
1329
|
}
|
|
1099
|
-
},
|
|
1330
|
+
}, _callee23, this, [[0, 9]]);
|
|
1100
1331
|
}));
|
|
1101
|
-
function loadFiles(
|
|
1332
|
+
function loadFiles(_x12) {
|
|
1102
1333
|
return _loadFiles.apply(this, arguments);
|
|
1103
1334
|
}
|
|
1104
1335
|
return loadFiles;
|
|
@@ -1114,42 +1345,42 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1114
1345
|
}, {
|
|
1115
1346
|
key: "create",
|
|
1116
1347
|
value: (function () {
|
|
1117
|
-
var _create = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1348
|
+
var _create = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(type) {
|
|
1118
1349
|
var dataHash,
|
|
1119
1350
|
options,
|
|
1120
1351
|
response,
|
|
1121
1352
|
record,
|
|
1122
|
-
|
|
1123
|
-
return _regeneratorRuntime().wrap(function
|
|
1124
|
-
while (1) switch (
|
|
1353
|
+
_args24 = arguments;
|
|
1354
|
+
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
1355
|
+
while (1) switch (_context24.prev = _context24.next) {
|
|
1125
1356
|
case 0:
|
|
1126
|
-
dataHash =
|
|
1127
|
-
options =
|
|
1128
|
-
|
|
1129
|
-
|
|
1357
|
+
dataHash = _args24.length > 1 && _args24[1] !== undefined ? _args24[1] : {};
|
|
1358
|
+
options = _args24.length > 2 && _args24[2] !== undefined ? _args24[2] : {};
|
|
1359
|
+
_context24.prev = 2;
|
|
1360
|
+
_context24.next = 5;
|
|
1130
1361
|
return this.axios.post('/object_service/createObject', [type, dataHash]);
|
|
1131
1362
|
case 5:
|
|
1132
|
-
response =
|
|
1363
|
+
response = _context24.sent;
|
|
1133
1364
|
record = response.data;
|
|
1134
1365
|
if (dataHash) {
|
|
1135
1366
|
record.data = dataHash;
|
|
1136
1367
|
}
|
|
1137
|
-
return
|
|
1368
|
+
return _context24.abrupt("return", new _rbt_object["default"](record, this.axios, {
|
|
1138
1369
|
isNew: true,
|
|
1139
1370
|
websocketClient: this.websocketClient,
|
|
1140
1371
|
enableRealtime: options.enableRealtime || false
|
|
1141
1372
|
}));
|
|
1142
1373
|
case 11:
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
return
|
|
1374
|
+
_context24.prev = 11;
|
|
1375
|
+
_context24.t0 = _context24["catch"](2);
|
|
1376
|
+
return _context24.abrupt("return", this._handleError(_context24.t0));
|
|
1146
1377
|
case 14:
|
|
1147
1378
|
case "end":
|
|
1148
|
-
return
|
|
1379
|
+
return _context24.stop();
|
|
1149
1380
|
}
|
|
1150
|
-
},
|
|
1381
|
+
}, _callee24, this, [[2, 11]]);
|
|
1151
1382
|
}));
|
|
1152
|
-
function create(
|
|
1383
|
+
function create(_x13) {
|
|
1153
1384
|
return _create.apply(this, arguments);
|
|
1154
1385
|
}
|
|
1155
1386
|
return create;
|
|
@@ -1192,8 +1423,8 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1192
1423
|
}, {
|
|
1193
1424
|
key: "query",
|
|
1194
1425
|
value: (function () {
|
|
1195
|
-
var _query = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1196
|
-
var
|
|
1426
|
+
var _query = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(type) {
|
|
1427
|
+
var _this7 = this;
|
|
1197
1428
|
var params,
|
|
1198
1429
|
paramsKey,
|
|
1199
1430
|
validParams,
|
|
@@ -1205,12 +1436,12 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1205
1436
|
cacheEntry,
|
|
1206
1437
|
responsePromise,
|
|
1207
1438
|
processingPromise,
|
|
1208
|
-
|
|
1209
|
-
return _regeneratorRuntime().wrap(function
|
|
1210
|
-
while (1) switch (
|
|
1439
|
+
_args25 = arguments;
|
|
1440
|
+
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
1441
|
+
while (1) switch (_context25.prev = _context25.next) {
|
|
1211
1442
|
case 0:
|
|
1212
|
-
params =
|
|
1213
|
-
|
|
1443
|
+
params = _args25.length > 1 && _args25[1] !== undefined ? _args25[1] : {};
|
|
1444
|
+
_context25.prev = 1;
|
|
1214
1445
|
//console.log('RBTAPI.query INIT', type, params);
|
|
1215
1446
|
// Validate parameters - reject invalid parameter names
|
|
1216
1447
|
validParams = ['type', 'where', 'orderBy', 'limit', 'resolveReferences', 'requestAttrs', 'excludeAttrs', 'timeout', 'enableRealtime'];
|
|
@@ -1218,7 +1449,7 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1218
1449
|
return !validParams.includes(key);
|
|
1219
1450
|
});
|
|
1220
1451
|
if (!(invalidParams.length > 0)) {
|
|
1221
|
-
|
|
1452
|
+
_context25.next = 6;
|
|
1222
1453
|
break;
|
|
1223
1454
|
}
|
|
1224
1455
|
throw new Error("Invalid query parameter(s): ".concat(invalidParams.join(', '), ". Valid parameters are: ").concat(validParams.join(', ')));
|
|
@@ -1245,19 +1476,19 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1245
1476
|
paramsKey = JSON.stringify(mergedParams);
|
|
1246
1477
|
cacheEntry = this.requestCache[paramsKey];
|
|
1247
1478
|
if (!(cacheEntry && currentTime - cacheEntry.time < 10000)) {
|
|
1248
|
-
|
|
1479
|
+
_context25.next = 16;
|
|
1249
1480
|
break;
|
|
1250
1481
|
}
|
|
1251
|
-
return
|
|
1482
|
+
return _context25.abrupt("return", cacheEntry.val);
|
|
1252
1483
|
case 16:
|
|
1253
1484
|
// Create the response promise
|
|
1254
1485
|
responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]); // Cache the promise of processing data, not just the raw response
|
|
1255
1486
|
processingPromise = responsePromise.then(function (response) {
|
|
1256
|
-
return
|
|
1487
|
+
return _this7._processResponseData(response, params);
|
|
1257
1488
|
})["catch"](function (e) {
|
|
1258
|
-
delete
|
|
1489
|
+
delete _this7.requestCache[paramsKey]; // Ensure cache cleanup on failure
|
|
1259
1490
|
//console.log('RBTAPI.query ERROR (Processing)', paramsKey, e);
|
|
1260
|
-
return
|
|
1491
|
+
return _this7._handleError(e);
|
|
1261
1492
|
}); // Store the promise of the processed data in the cache
|
|
1262
1493
|
this.requestCache[paramsKey] = {
|
|
1263
1494
|
val: processingPromise,
|
|
@@ -1265,23 +1496,23 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1265
1496
|
};
|
|
1266
1497
|
|
|
1267
1498
|
// Await the processing promise for this call to get processed data
|
|
1268
|
-
|
|
1499
|
+
_context25.next = 21;
|
|
1269
1500
|
return processingPromise;
|
|
1270
1501
|
case 21:
|
|
1271
|
-
return
|
|
1502
|
+
return _context25.abrupt("return", _context25.sent);
|
|
1272
1503
|
case 24:
|
|
1273
|
-
|
|
1274
|
-
|
|
1504
|
+
_context25.prev = 24;
|
|
1505
|
+
_context25.t0 = _context25["catch"](1);
|
|
1275
1506
|
delete this.requestCache[paramsKey]; // Ensure cache cleanup on error
|
|
1276
1507
|
//console.log('RBTAPI.query ERROR', paramsKey, e);
|
|
1277
|
-
return
|
|
1508
|
+
return _context25.abrupt("return", this._handleError(_context25.t0));
|
|
1278
1509
|
case 28:
|
|
1279
1510
|
case "end":
|
|
1280
|
-
return
|
|
1511
|
+
return _context25.stop();
|
|
1281
1512
|
}
|
|
1282
|
-
},
|
|
1513
|
+
}, _callee25, this, [[1, 24]]);
|
|
1283
1514
|
}));
|
|
1284
|
-
function query(
|
|
1515
|
+
function query(_x14) {
|
|
1285
1516
|
return _query.apply(this, arguments);
|
|
1286
1517
|
}
|
|
1287
1518
|
return query;
|
|
@@ -1289,7 +1520,7 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1289
1520
|
}, {
|
|
1290
1521
|
key: "_processResponseData",
|
|
1291
1522
|
value: function _processResponseData(response) {
|
|
1292
|
-
var
|
|
1523
|
+
var _this8 = this;
|
|
1293
1524
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1294
1525
|
if (response.data.ok === false) {
|
|
1295
1526
|
return this._handleError(response);
|
|
@@ -1303,7 +1534,7 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1303
1534
|
websocketClient = this.getWebSocketClient();
|
|
1304
1535
|
}
|
|
1305
1536
|
response.data.items = response.data.items.map(function (record) {
|
|
1306
|
-
return new _rbt_object["default"](record,
|
|
1537
|
+
return new _rbt_object["default"](record, _this8.axios, {
|
|
1307
1538
|
websocketClient: websocketClient,
|
|
1308
1539
|
enableRealtime: options.enableRealtime || false
|
|
1309
1540
|
});
|
|
@@ -1325,8 +1556,8 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1325
1556
|
}, {
|
|
1326
1557
|
key: "load",
|
|
1327
1558
|
value: (function () {
|
|
1328
|
-
var _load = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1329
|
-
var
|
|
1559
|
+
var _load = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(type, ids) {
|
|
1560
|
+
var _this9 = this;
|
|
1330
1561
|
var params,
|
|
1331
1562
|
mergedParams,
|
|
1332
1563
|
cachedObjects,
|
|
@@ -1358,17 +1589,17 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1358
1589
|
pendingKey,
|
|
1359
1590
|
missLogKey,
|
|
1360
1591
|
loadPromise,
|
|
1361
|
-
|
|
1362
|
-
return _regeneratorRuntime().wrap(function
|
|
1363
|
-
while (1) switch (
|
|
1592
|
+
_args27 = arguments;
|
|
1593
|
+
return _regeneratorRuntime().wrap(function _callee27$(_context27) {
|
|
1594
|
+
while (1) switch (_context27.prev = _context27.next) {
|
|
1364
1595
|
case 0:
|
|
1365
|
-
params =
|
|
1596
|
+
params = _args27.length > 2 && _args27[2] !== undefined ? _args27[2] : {};
|
|
1366
1597
|
if (type == '<@iac.user>') {
|
|
1367
1598
|
debugger;
|
|
1368
1599
|
}
|
|
1369
|
-
|
|
1600
|
+
_context27.prev = 2;
|
|
1370
1601
|
if (!Array.isArray(ids)) {
|
|
1371
|
-
|
|
1602
|
+
_context27.next = 25;
|
|
1372
1603
|
break;
|
|
1373
1604
|
}
|
|
1374
1605
|
// For array requests, check cache for each ID and only load missing ones
|
|
@@ -1405,7 +1636,7 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1405
1636
|
}
|
|
1406
1637
|
loadedObjects = [];
|
|
1407
1638
|
if (!(missingIds.length > 0)) {
|
|
1408
|
-
|
|
1639
|
+
_context27.next = 19;
|
|
1409
1640
|
break;
|
|
1410
1641
|
}
|
|
1411
1642
|
// Only log bulk cache miss once
|
|
@@ -1419,10 +1650,10 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1419
1650
|
mergedParams = _objectSpread(_objectSpread({}, queryParams), {}, {
|
|
1420
1651
|
where: "id IN (\"".concat(missingIds.join("\",\""), "\")")
|
|
1421
1652
|
});
|
|
1422
|
-
|
|
1653
|
+
_context27.next = 16;
|
|
1423
1654
|
return this.query(type, mergedParams);
|
|
1424
1655
|
case 16:
|
|
1425
|
-
loadedObjects =
|
|
1656
|
+
loadedObjects = _context27.sent;
|
|
1426
1657
|
// Cache the newly loaded objects
|
|
1427
1658
|
_iterator4 = _createForOfIteratorHelper(loadedObjects);
|
|
1428
1659
|
try {
|
|
@@ -1464,13 +1695,13 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1464
1695
|
} finally {
|
|
1465
1696
|
_iterator5.f();
|
|
1466
1697
|
}
|
|
1467
|
-
return
|
|
1698
|
+
return _context27.abrupt("return", result);
|
|
1468
1699
|
case 25:
|
|
1469
1700
|
// For single object requests, check cache first
|
|
1470
1701
|
_cacheKey3 = "".concat(type, ":").concat(ids);
|
|
1471
1702
|
_cached = this._objectCache.get(_cacheKey3);
|
|
1472
1703
|
if (!_cached) {
|
|
1473
|
-
|
|
1704
|
+
_context27.next = 32;
|
|
1474
1705
|
break;
|
|
1475
1706
|
}
|
|
1476
1707
|
// Only log cache hits once per object to reduce spam
|
|
@@ -1483,18 +1714,18 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1483
1714
|
if (params.enableRealtime && !_cached._realtime) {
|
|
1484
1715
|
_cached._initRealtime();
|
|
1485
1716
|
}
|
|
1486
|
-
return
|
|
1717
|
+
return _context27.abrupt("return", _cached);
|
|
1487
1718
|
case 32:
|
|
1488
1719
|
// Check if we're already loading this object
|
|
1489
1720
|
pendingKey = "".concat(type, ":").concat(ids);
|
|
1490
1721
|
if (!this._pendingLoads.has(pendingKey)) {
|
|
1491
|
-
|
|
1722
|
+
_context27.next = 37;
|
|
1492
1723
|
break;
|
|
1493
1724
|
}
|
|
1494
|
-
|
|
1725
|
+
_context27.next = 36;
|
|
1495
1726
|
return this._pendingLoads.get(pendingKey);
|
|
1496
1727
|
case 36:
|
|
1497
|
-
return
|
|
1728
|
+
return _context27.abrupt("return", _context27.sent);
|
|
1498
1729
|
case 37:
|
|
1499
1730
|
// Only log cache miss once per object to reduce spam
|
|
1500
1731
|
missLogKey = "miss:".concat(_cacheKey3);
|
|
@@ -1503,63 +1734,63 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1503
1734
|
}
|
|
1504
1735
|
|
|
1505
1736
|
// Create the loading promise and store it to prevent duplicate requests
|
|
1506
|
-
loadPromise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1737
|
+
loadPromise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
|
|
1507
1738
|
var _enableRealtime, _queryParams, res, _obj2, _setLogKey;
|
|
1508
|
-
return _regeneratorRuntime().wrap(function
|
|
1509
|
-
while (1) switch (
|
|
1739
|
+
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
1740
|
+
while (1) switch (_context26.prev = _context26.next) {
|
|
1510
1741
|
case 0:
|
|
1511
|
-
|
|
1742
|
+
_context26.prev = 0;
|
|
1512
1743
|
// Remove load-specific params that shouldn't be passed to query
|
|
1513
1744
|
_enableRealtime = params.enableRealtime, _queryParams = _objectWithoutProperties(params, _excluded2);
|
|
1514
1745
|
mergedParams = _objectSpread(_objectSpread({}, _queryParams), {}, {
|
|
1515
1746
|
where: "id=\"".concat(ids, "\"")
|
|
1516
1747
|
});
|
|
1517
|
-
|
|
1518
|
-
return
|
|
1748
|
+
_context26.next = 5;
|
|
1749
|
+
return _this9.query(type, mergedParams);
|
|
1519
1750
|
case 5:
|
|
1520
|
-
res =
|
|
1751
|
+
res = _context26.sent;
|
|
1521
1752
|
_obj2 = res[0];
|
|
1522
1753
|
if (_obj2) {
|
|
1523
1754
|
// Cache the loaded object
|
|
1524
|
-
|
|
1755
|
+
_this9._objectCache.set(_cacheKey3, _obj2);
|
|
1525
1756
|
|
|
1526
1757
|
// Only log cache set once per object to reduce spam
|
|
1527
1758
|
_setLogKey = "set:".concat(_cacheKey3);
|
|
1528
|
-
if (!
|
|
1529
|
-
|
|
1759
|
+
if (!_this9._loggedCacheEvents.has(_setLogKey)) {
|
|
1760
|
+
_this9._loggedCacheEvents.add(_setLogKey);
|
|
1530
1761
|
}
|
|
1531
1762
|
}
|
|
1532
|
-
return
|
|
1763
|
+
return _context26.abrupt("return", _obj2);
|
|
1533
1764
|
case 9:
|
|
1534
|
-
|
|
1765
|
+
_context26.prev = 9;
|
|
1535
1766
|
// Remove from pending loads
|
|
1536
|
-
|
|
1537
|
-
return
|
|
1767
|
+
_this9._pendingLoads["delete"](pendingKey);
|
|
1768
|
+
return _context26.finish(9);
|
|
1538
1769
|
case 12:
|
|
1539
1770
|
case "end":
|
|
1540
|
-
return
|
|
1771
|
+
return _context26.stop();
|
|
1541
1772
|
}
|
|
1542
|
-
},
|
|
1773
|
+
}, _callee26, null, [[0,, 9, 12]]);
|
|
1543
1774
|
}))(); // Store the promise so other concurrent requests can await it
|
|
1544
1775
|
this._pendingLoads.set(pendingKey, loadPromise);
|
|
1545
|
-
|
|
1776
|
+
_context27.next = 43;
|
|
1546
1777
|
return loadPromise;
|
|
1547
1778
|
case 43:
|
|
1548
|
-
return
|
|
1779
|
+
return _context27.abrupt("return", _context27.sent);
|
|
1549
1780
|
case 44:
|
|
1550
|
-
|
|
1781
|
+
_context27.next = 49;
|
|
1551
1782
|
break;
|
|
1552
1783
|
case 46:
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
return
|
|
1784
|
+
_context27.prev = 46;
|
|
1785
|
+
_context27.t0 = _context27["catch"](2);
|
|
1786
|
+
return _context27.abrupt("return", this._handleError(_context27.t0));
|
|
1556
1787
|
case 49:
|
|
1557
1788
|
case "end":
|
|
1558
|
-
return
|
|
1789
|
+
return _context27.stop();
|
|
1559
1790
|
}
|
|
1560
|
-
},
|
|
1791
|
+
}, _callee27, this, [[2, 46]]);
|
|
1561
1792
|
}));
|
|
1562
|
-
function load(
|
|
1793
|
+
function load(_x15, _x16) {
|
|
1563
1794
|
return _load.apply(this, arguments);
|
|
1564
1795
|
}
|
|
1565
1796
|
return load;
|
|
@@ -1635,11 +1866,11 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1635
1866
|
}, {
|
|
1636
1867
|
key: "getCacheStatus",
|
|
1637
1868
|
value: function getCacheStatus() {
|
|
1638
|
-
var cacheEntries = Array.from(this._objectCache.entries()).map(function (
|
|
1869
|
+
var cacheEntries = Array.from(this._objectCache.entries()).map(function (_ref7) {
|
|
1639
1870
|
var _obj$_internalData;
|
|
1640
|
-
var
|
|
1641
|
-
key =
|
|
1642
|
-
obj =
|
|
1871
|
+
var _ref8 = _slicedToArray(_ref7, 2),
|
|
1872
|
+
key = _ref8[0],
|
|
1873
|
+
obj = _ref8[1];
|
|
1643
1874
|
return {
|
|
1644
1875
|
key: key,
|
|
1645
1876
|
id: obj.id,
|
|
@@ -1677,7 +1908,7 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1677
1908
|
}, {
|
|
1678
1909
|
key: "runTask",
|
|
1679
1910
|
value: (function () {
|
|
1680
|
-
var _runTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1911
|
+
var _runTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
|
|
1681
1912
|
var params,
|
|
1682
1913
|
callbacks,
|
|
1683
1914
|
onProgress,
|
|
@@ -1692,20 +1923,20 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1692
1923
|
message,
|
|
1693
1924
|
output,
|
|
1694
1925
|
errorResponse,
|
|
1695
|
-
|
|
1696
|
-
return _regeneratorRuntime().wrap(function
|
|
1697
|
-
while (1) switch (
|
|
1926
|
+
_args28 = arguments;
|
|
1927
|
+
return _regeneratorRuntime().wrap(function _callee28$(_context28) {
|
|
1928
|
+
while (1) switch (_context28.prev = _context28.next) {
|
|
1698
1929
|
case 0:
|
|
1699
|
-
params =
|
|
1700
|
-
callbacks =
|
|
1930
|
+
params = _args28.length > 0 && _args28[0] !== undefined ? _args28[0] : {};
|
|
1931
|
+
callbacks = _args28.length > 1 && _args28[1] !== undefined ? _args28[1] : {};
|
|
1701
1932
|
onProgress = callbacks.onProgress, onError = callbacks.onError, onStopped = callbacks.onStopped, onWaiting = callbacks.onWaiting, onDone = callbacks.onDone;
|
|
1702
|
-
|
|
1703
|
-
|
|
1933
|
+
_context28.prev = 3;
|
|
1934
|
+
_context28.next = 6;
|
|
1704
1935
|
return this.post('/task_service/runChain', params);
|
|
1705
1936
|
case 6:
|
|
1706
|
-
response =
|
|
1937
|
+
response = _context28.sent;
|
|
1707
1938
|
if (response) {
|
|
1708
|
-
|
|
1939
|
+
_context28.next = 9;
|
|
1709
1940
|
break;
|
|
1710
1941
|
}
|
|
1711
1942
|
throw new Error('Invalid server response');
|
|
@@ -1713,7 +1944,7 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1713
1944
|
// Validate response structure
|
|
1714
1945
|
ok = response.ok, jobId = response.jobId, status = response.status, message = response.message, output = response.output;
|
|
1715
1946
|
if (!(!ok || typeof jobId !== 'string' || typeof status !== 'string')) {
|
|
1716
|
-
|
|
1947
|
+
_context28.next = 12;
|
|
1717
1948
|
break;
|
|
1718
1949
|
}
|
|
1719
1950
|
throw new Error('Invalid response structure');
|
|
@@ -1739,7 +1970,7 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1739
1970
|
//console.log('Finish (request) ',response); s
|
|
1740
1971
|
onDone(response);
|
|
1741
1972
|
}
|
|
1742
|
-
return
|
|
1973
|
+
return _context28.abrupt("return", {
|
|
1743
1974
|
ok: ok,
|
|
1744
1975
|
jobId: jobId,
|
|
1745
1976
|
status: status,
|
|
@@ -1747,21 +1978,21 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1747
1978
|
output: output
|
|
1748
1979
|
});
|
|
1749
1980
|
case 20:
|
|
1750
|
-
|
|
1751
|
-
|
|
1981
|
+
_context28.prev = 20;
|
|
1982
|
+
_context28.t0 = _context28["catch"](3);
|
|
1752
1983
|
// Standardize error format to match task response object
|
|
1753
1984
|
// Support RbtError format with label and message
|
|
1754
1985
|
errorResponse = {
|
|
1755
1986
|
ok: false,
|
|
1756
1987
|
jobId: null,
|
|
1757
1988
|
status: 'ERROR',
|
|
1758
|
-
message:
|
|
1759
|
-
label:
|
|
1989
|
+
message: _context28.t0.message || _context28.t0.toString() || 'Unknown error',
|
|
1990
|
+
label: _context28.t0.label || _context28.t0.name || 'Error',
|
|
1760
1991
|
output: {
|
|
1761
|
-
error:
|
|
1762
|
-
label:
|
|
1763
|
-
stack:
|
|
1764
|
-
originalError:
|
|
1992
|
+
error: _context28.t0.message,
|
|
1993
|
+
label: _context28.t0.label,
|
|
1994
|
+
stack: _context28.t0.stack,
|
|
1995
|
+
originalError: _context28.t0
|
|
1765
1996
|
}
|
|
1766
1997
|
};
|
|
1767
1998
|
if (typeof onError === 'function') {
|
|
@@ -1769,12 +2000,12 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1769
2000
|
} else {
|
|
1770
2001
|
console.error('Error in runTask:', errorResponse.message);
|
|
1771
2002
|
}
|
|
1772
|
-
return
|
|
2003
|
+
return _context28.abrupt("return", errorResponse);
|
|
1773
2004
|
case 25:
|
|
1774
2005
|
case "end":
|
|
1775
|
-
return
|
|
2006
|
+
return _context28.stop();
|
|
1776
2007
|
}
|
|
1777
|
-
},
|
|
2008
|
+
}, _callee28, this, [[3, 20]]);
|
|
1778
2009
|
}));
|
|
1779
2010
|
function runTask() {
|
|
1780
2011
|
return _runTask.apply(this, arguments);
|
|
@@ -1784,37 +2015,37 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1784
2015
|
}, {
|
|
1785
2016
|
key: "stopJob",
|
|
1786
2017
|
value: function () {
|
|
1787
|
-
var _stopJob = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2018
|
+
var _stopJob = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
|
|
1788
2019
|
var params,
|
|
1789
2020
|
callbacks,
|
|
1790
2021
|
response,
|
|
1791
|
-
|
|
1792
|
-
return _regeneratorRuntime().wrap(function
|
|
1793
|
-
while (1) switch (
|
|
2022
|
+
_args29 = arguments;
|
|
2023
|
+
return _regeneratorRuntime().wrap(function _callee29$(_context29) {
|
|
2024
|
+
while (1) switch (_context29.prev = _context29.next) {
|
|
1794
2025
|
case 0:
|
|
1795
|
-
params =
|
|
1796
|
-
callbacks =
|
|
1797
|
-
|
|
1798
|
-
|
|
2026
|
+
params = _args29.length > 0 && _args29[0] !== undefined ? _args29[0] : {};
|
|
2027
|
+
callbacks = _args29.length > 1 && _args29[1] !== undefined ? _args29[1] : {};
|
|
2028
|
+
_context29.prev = 2;
|
|
2029
|
+
_context29.next = 5;
|
|
1799
2030
|
return this.post('/task_service/stopJob', params);
|
|
1800
2031
|
case 5:
|
|
1801
|
-
response =
|
|
2032
|
+
response = _context29.sent;
|
|
1802
2033
|
if (response) {
|
|
1803
|
-
|
|
2034
|
+
_context29.next = 8;
|
|
1804
2035
|
break;
|
|
1805
2036
|
}
|
|
1806
2037
|
throw new Error('Invalid server response');
|
|
1807
2038
|
case 8:
|
|
1808
|
-
return
|
|
2039
|
+
return _context29.abrupt("return", true);
|
|
1809
2040
|
case 11:
|
|
1810
|
-
|
|
1811
|
-
|
|
2041
|
+
_context29.prev = 11;
|
|
2042
|
+
_context29.t0 = _context29["catch"](2);
|
|
1812
2043
|
throw 'Error in stopJob';
|
|
1813
2044
|
case 14:
|
|
1814
2045
|
case "end":
|
|
1815
|
-
return
|
|
2046
|
+
return _context29.stop();
|
|
1816
2047
|
}
|
|
1817
|
-
},
|
|
2048
|
+
}, _callee29, this, [[2, 11]]);
|
|
1818
2049
|
}));
|
|
1819
2050
|
function stopJob() {
|
|
1820
2051
|
return _stopJob.apply(this, arguments);
|
|
@@ -1862,26 +2093,26 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1862
2093
|
}, {
|
|
1863
2094
|
key: "pollTaskProgress",
|
|
1864
2095
|
value: (function () {
|
|
1865
|
-
var _pollTaskProgress = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
1866
|
-
var
|
|
2096
|
+
var _pollTaskProgress = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(jobId, callbacks) {
|
|
2097
|
+
var _this10 = this;
|
|
1867
2098
|
var onProgress, onError, onStopped, onWaiting, onDone, _callbacks$pollingInt, pollingInterval, checkProgress;
|
|
1868
|
-
return _regeneratorRuntime().wrap(function
|
|
1869
|
-
while (1) switch (
|
|
2099
|
+
return _regeneratorRuntime().wrap(function _callee31$(_context31) {
|
|
2100
|
+
while (1) switch (_context31.prev = _context31.next) {
|
|
1870
2101
|
case 0:
|
|
1871
2102
|
onProgress = callbacks.onProgress, onError = callbacks.onError, onStopped = callbacks.onStopped, onWaiting = callbacks.onWaiting, onDone = callbacks.onDone, _callbacks$pollingInt = callbacks.pollingInterval, pollingInterval = _callbacks$pollingInt === void 0 ? 2000 : _callbacks$pollingInt;
|
|
1872
|
-
|
|
2103
|
+
_context31.prev = 1;
|
|
1873
2104
|
checkProgress = /*#__PURE__*/function () {
|
|
1874
|
-
var
|
|
2105
|
+
var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30() {
|
|
1875
2106
|
var response;
|
|
1876
|
-
return _regeneratorRuntime().wrap(function
|
|
1877
|
-
while (1) switch (
|
|
2107
|
+
return _regeneratorRuntime().wrap(function _callee30$(_context30) {
|
|
2108
|
+
while (1) switch (_context30.prev = _context30.next) {
|
|
1878
2109
|
case 0:
|
|
1879
|
-
|
|
1880
|
-
return
|
|
2110
|
+
_context30.next = 2;
|
|
2111
|
+
return _this10.get("/task_service/pollChainProgress", {
|
|
1881
2112
|
jobId: jobId
|
|
1882
2113
|
});
|
|
1883
2114
|
case 2:
|
|
1884
|
-
response =
|
|
2115
|
+
response = _context30.sent;
|
|
1885
2116
|
// If the task is still in progress, start polling for updates
|
|
1886
2117
|
if (response.status === 'DONE' && onDone) {
|
|
1887
2118
|
// Provide the current progress to the callback function
|
|
@@ -1890,7 +2121,7 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1890
2121
|
}
|
|
1891
2122
|
if (response.status === 'ERROR' && onError) {
|
|
1892
2123
|
// Normalize error response to have consistent message/label at top level
|
|
1893
|
-
onError(
|
|
2124
|
+
onError(_this10._normalizeErrorResponse(response));
|
|
1894
2125
|
}
|
|
1895
2126
|
if (response.status === 'STOPPED' && onStopped) {
|
|
1896
2127
|
// Provide the current progress to the callback function
|
|
@@ -1912,28 +2143,28 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1912
2143
|
}
|
|
1913
2144
|
case 9:
|
|
1914
2145
|
case "end":
|
|
1915
|
-
return
|
|
2146
|
+
return _context30.stop();
|
|
1916
2147
|
}
|
|
1917
|
-
},
|
|
2148
|
+
}, _callee30);
|
|
1918
2149
|
}));
|
|
1919
2150
|
return function checkProgress() {
|
|
1920
|
-
return
|
|
2151
|
+
return _ref9.apply(this, arguments);
|
|
1921
2152
|
};
|
|
1922
2153
|
}();
|
|
1923
2154
|
checkProgress();
|
|
1924
|
-
|
|
2155
|
+
_context31.next = 9;
|
|
1925
2156
|
break;
|
|
1926
2157
|
case 6:
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
return
|
|
2158
|
+
_context31.prev = 6;
|
|
2159
|
+
_context31.t0 = _context31["catch"](1);
|
|
2160
|
+
return _context31.abrupt("return", this._handleError(_context31.t0));
|
|
1930
2161
|
case 9:
|
|
1931
2162
|
case "end":
|
|
1932
|
-
return
|
|
2163
|
+
return _context31.stop();
|
|
1933
2164
|
}
|
|
1934
|
-
},
|
|
2165
|
+
}, _callee31, this, [[1, 6]]);
|
|
1935
2166
|
}));
|
|
1936
|
-
function pollTaskProgress(
|
|
2167
|
+
function pollTaskProgress(_x17, _x18) {
|
|
1937
2168
|
return _pollTaskProgress.apply(this, arguments);
|
|
1938
2169
|
}
|
|
1939
2170
|
return pollTaskProgress;
|
|
@@ -1954,18 +2185,18 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1954
2185
|
}, {
|
|
1955
2186
|
key: "get",
|
|
1956
2187
|
value: (function () {
|
|
1957
|
-
var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2188
|
+
var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(endpoint) {
|
|
1958
2189
|
var params,
|
|
1959
2190
|
customHeaders,
|
|
1960
2191
|
config,
|
|
1961
2192
|
response,
|
|
1962
|
-
|
|
1963
|
-
return _regeneratorRuntime().wrap(function
|
|
1964
|
-
while (1) switch (
|
|
2193
|
+
_args32 = arguments;
|
|
2194
|
+
return _regeneratorRuntime().wrap(function _callee32$(_context32) {
|
|
2195
|
+
while (1) switch (_context32.prev = _context32.next) {
|
|
1965
2196
|
case 0:
|
|
1966
|
-
params =
|
|
1967
|
-
customHeaders =
|
|
1968
|
-
|
|
2197
|
+
params = _args32.length > 1 && _args32[1] !== undefined ? _args32[1] : {};
|
|
2198
|
+
customHeaders = _args32.length > 2 && _args32[2] !== undefined ? _args32[2] : null;
|
|
2199
|
+
_context32.prev = 2;
|
|
1969
2200
|
// Build request config
|
|
1970
2201
|
config = {
|
|
1971
2202
|
params: params
|
|
@@ -1980,28 +2211,28 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
1980
2211
|
// Otherwise, don't set config.headers at all - let axios use its defaults
|
|
1981
2212
|
|
|
1982
2213
|
// Make the GET request using Axios
|
|
1983
|
-
|
|
2214
|
+
_context32.next = 7;
|
|
1984
2215
|
return this.axios.get(endpoint, config);
|
|
1985
2216
|
case 7:
|
|
1986
|
-
response =
|
|
2217
|
+
response = _context32.sent;
|
|
1987
2218
|
if (!(response.data.ok === false)) {
|
|
1988
|
-
|
|
2219
|
+
_context32.next = 10;
|
|
1989
2220
|
break;
|
|
1990
2221
|
}
|
|
1991
|
-
return
|
|
2222
|
+
return _context32.abrupt("return", this._handleError(response));
|
|
1992
2223
|
case 10:
|
|
1993
|
-
return
|
|
2224
|
+
return _context32.abrupt("return", response.data);
|
|
1994
2225
|
case 13:
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
return
|
|
2226
|
+
_context32.prev = 13;
|
|
2227
|
+
_context32.t0 = _context32["catch"](2);
|
|
2228
|
+
return _context32.abrupt("return", this._handleError(_context32.t0));
|
|
1998
2229
|
case 16:
|
|
1999
2230
|
case "end":
|
|
2000
|
-
return
|
|
2231
|
+
return _context32.stop();
|
|
2001
2232
|
}
|
|
2002
|
-
},
|
|
2233
|
+
}, _callee32, this, [[2, 13]]);
|
|
2003
2234
|
}));
|
|
2004
|
-
function get(
|
|
2235
|
+
function get(_x19) {
|
|
2005
2236
|
return _get.apply(this, arguments);
|
|
2006
2237
|
}
|
|
2007
2238
|
return get;
|
|
@@ -2022,44 +2253,44 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
2022
2253
|
}, {
|
|
2023
2254
|
key: "post",
|
|
2024
2255
|
value: (function () {
|
|
2025
|
-
var _post = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
2256
|
+
var _post = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(endpoint) {
|
|
2026
2257
|
var data,
|
|
2027
2258
|
headers,
|
|
2028
2259
|
response,
|
|
2029
|
-
|
|
2030
|
-
return _regeneratorRuntime().wrap(function
|
|
2031
|
-
while (1) switch (
|
|
2260
|
+
_args33 = arguments;
|
|
2261
|
+
return _regeneratorRuntime().wrap(function _callee33$(_context33) {
|
|
2262
|
+
while (1) switch (_context33.prev = _context33.next) {
|
|
2032
2263
|
case 0:
|
|
2033
|
-
data =
|
|
2034
|
-
|
|
2264
|
+
data = _args33.length > 1 && _args33[1] !== undefined ? _args33[1] : {};
|
|
2265
|
+
_context33.prev = 1;
|
|
2035
2266
|
// Add the authToken to the headers
|
|
2036
2267
|
headers = {
|
|
2037
2268
|
authtoken: this.authtoken
|
|
2038
2269
|
}; // Make the POST request using Axios
|
|
2039
|
-
|
|
2270
|
+
_context33.next = 5;
|
|
2040
2271
|
return this.axios.post(endpoint, data, {
|
|
2041
2272
|
headers: headers
|
|
2042
2273
|
});
|
|
2043
2274
|
case 5:
|
|
2044
|
-
response =
|
|
2275
|
+
response = _context33.sent;
|
|
2045
2276
|
if (!(response.data.ok === false)) {
|
|
2046
|
-
|
|
2277
|
+
_context33.next = 8;
|
|
2047
2278
|
break;
|
|
2048
2279
|
}
|
|
2049
|
-
return
|
|
2280
|
+
return _context33.abrupt("return", this._handleError(response));
|
|
2050
2281
|
case 8:
|
|
2051
|
-
return
|
|
2282
|
+
return _context33.abrupt("return", response.data);
|
|
2052
2283
|
case 11:
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
return
|
|
2284
|
+
_context33.prev = 11;
|
|
2285
|
+
_context33.t0 = _context33["catch"](1);
|
|
2286
|
+
return _context33.abrupt("return", this._handleError(_context33.t0));
|
|
2056
2287
|
case 14:
|
|
2057
2288
|
case "end":
|
|
2058
|
-
return
|
|
2289
|
+
return _context33.stop();
|
|
2059
2290
|
}
|
|
2060
|
-
},
|
|
2291
|
+
}, _callee33, this, [[1, 11]]);
|
|
2061
2292
|
}));
|
|
2062
|
-
function post(
|
|
2293
|
+
function post(_x20) {
|
|
2063
2294
|
return _post.apply(this, arguments);
|
|
2064
2295
|
}
|
|
2065
2296
|
return post;
|