roboto-js 1.8.4 → 1.8.6
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/BUILD_NOTES.md +30 -0
- package/babel.config.json +13 -0
- package/dist/cjs/cookie_storage_adaptor.cjs +38 -84
- package/dist/cjs/index.cjs +21 -14
- package/dist/cjs/rbt_api.cjs +34 -97
- package/dist/cjs/rbt_object.cjs +5 -14
- package/dist/cjs/rbt_user.cjs +1 -3
- package/dist/cookie_storage_adaptor.js +415 -0
- package/dist/esm/cookie_storage_adaptor.js +354 -197
- package/dist/esm/index.js +604 -182
- package/dist/esm/rbt_api.js +1976 -1172
- package/dist/esm/rbt_file.js +222 -126
- package/dist/esm/rbt_metrics_api.js +166 -71
- package/dist/esm/rbt_object.js +1014 -708
- package/dist/esm/rbt_user.js +209 -138
- package/dist/index.js +594 -0
- package/dist/rbt_api.js +2115 -0
- package/dist/rbt_file.js +223 -0
- package/dist/rbt_metrics_api.js +200 -0
- package/dist/rbt_object.js +1110 -0
- package/dist/rbt_user.js +235 -0
- package/package.json +4 -3
- package/src/index.js +21 -11
- package/src/rbt_api.js +9 -0
package/dist/esm/rbt_api.js
CHANGED
|
@@ -1,18 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = void 0;
|
|
7
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
8
|
+
var _cryptoJs = _interopRequireDefault(require("crypto-js"));
|
|
9
|
+
var _rbt_object = _interopRequireDefault(require("./rbt_object.js"));
|
|
10
|
+
var _rbt_user = _interopRequireDefault(require("./rbt_user.js"));
|
|
11
|
+
var _rbt_file = _interopRequireDefault(require("./rbt_file.js"));
|
|
12
|
+
var _lodash = _interopRequireDefault(require("lodash"));
|
|
13
|
+
var _idb = require("idb");
|
|
14
|
+
var _excluded = ["enableRealtime"],
|
|
15
|
+
_excluded2 = ["enableRealtime"];
|
|
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
|
+
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
|
+
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
|
+
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
|
+
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
|
+
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; }
|
|
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
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
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."); }
|
|
26
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
27
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
28
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, 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 normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
29
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
30
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
31
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
32
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
33
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
34
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
35
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
36
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
37
|
+
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); }
|
|
38
|
+
var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
39
|
+
function RbtApi(_ref) {
|
|
40
|
+
var baseUrl = _ref.baseUrl,
|
|
41
|
+
accesskey = _ref.accesskey,
|
|
42
|
+
_ref$authtoken = _ref.authtoken,
|
|
43
|
+
authtoken = _ref$authtoken === void 0 ? null : _ref$authtoken,
|
|
44
|
+
_ref$apikey = _ref.apikey,
|
|
45
|
+
apikey = _ref$apikey === void 0 ? null : _ref$apikey,
|
|
46
|
+
_ref$localStorageAdap = _ref.localStorageAdaptor,
|
|
47
|
+
localStorageAdaptor = _ref$localStorageAdap === void 0 ? null : _ref$localStorageAdap;
|
|
48
|
+
_classCallCheck(this, RbtApi);
|
|
16
49
|
this.websocketClient = null;
|
|
17
50
|
|
|
18
51
|
// Object cache for sharing instances across multiple load() calls
|
|
@@ -23,7 +56,7 @@ export default class RbtApi {
|
|
|
23
56
|
|
|
24
57
|
// Track what we've already logged to reduce console spam
|
|
25
58
|
this._loggedCacheEvents = new Set();
|
|
26
|
-
this.axios =
|
|
59
|
+
this.axios = _axios["default"].create({
|
|
27
60
|
baseURL: baseUrl,
|
|
28
61
|
headers: {
|
|
29
62
|
'accesskey': accesskey
|
|
@@ -36,15 +69,23 @@ export default class RbtApi {
|
|
|
36
69
|
} else if (typeof localStorage != 'undefined') {
|
|
37
70
|
// browser based local storage
|
|
38
71
|
this.localStorageAdaptor = {
|
|
39
|
-
getItem:
|
|
40
|
-
|
|
41
|
-
|
|
72
|
+
getItem: function getItem(key) {
|
|
73
|
+
return Promise.resolve(localStorage.getItem(key));
|
|
74
|
+
},
|
|
75
|
+
setItem: function setItem(key, value) {
|
|
76
|
+
return Promise.resolve(localStorage.setItem(key, value));
|
|
77
|
+
},
|
|
78
|
+
removeItem: function removeItem(key) {
|
|
79
|
+
return Promise.resolve(localStorage.removeItem(key));
|
|
80
|
+
}
|
|
42
81
|
};
|
|
43
82
|
}
|
|
44
83
|
|
|
45
84
|
// Asynchronous browser hydration: set auth header and in-memory user
|
|
46
85
|
// Use storage adaptor if available, otherwise fallback to localStorage
|
|
47
|
-
this._initializeFromStorage()
|
|
86
|
+
this._initializeFromStorage()["catch"](function (e) {
|
|
87
|
+
return void 0;
|
|
88
|
+
});
|
|
48
89
|
this.localDb = null;
|
|
49
90
|
this.iac_session = null;
|
|
50
91
|
this.appServiceHost = baseUrl;
|
|
@@ -54,1238 +95,2001 @@ export default class RbtApi {
|
|
|
54
95
|
|
|
55
96
|
// Use the storageAdaptor to get the authToken, if available
|
|
56
97
|
this.initAuthToken(authtoken);
|
|
98
|
+
|
|
99
|
+
// Set apiKey synchronously if provided (don't wait for async initApiKey)
|
|
100
|
+
if (apikey) {
|
|
101
|
+
this.apikey = apikey;
|
|
102
|
+
this.axios.defaults.headers.common['apikey'] = this.apikey;
|
|
103
|
+
// ADD THIS LINE
|
|
104
|
+
}
|
|
57
105
|
this.initApiKey(apikey);
|
|
58
106
|
}
|
|
59
107
|
|
|
60
108
|
// Initialize authtoken and user from storage (cookies or localStorage)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
109
|
+
_createClass(RbtApi, [{
|
|
110
|
+
key: "_initializeFromStorage",
|
|
111
|
+
value: function () {
|
|
112
|
+
var _initializeFromStorage2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
113
|
+
var token, cookies, _iterator, _step, cookie, _cookie$trim$split, _cookie$trim$split2, name, value, cachedUser, parsed;
|
|
114
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
115
|
+
while (1) switch (_context.prev = _context.next) {
|
|
116
|
+
case 0:
|
|
117
|
+
if (this.localStorageAdaptor) {
|
|
118
|
+
_context.next = 2;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
return _context.abrupt("return");
|
|
122
|
+
case 2:
|
|
123
|
+
_context.prev = 2;
|
|
124
|
+
_context.next = 5;
|
|
125
|
+
return this.localStorageAdaptor.getItem('authtoken');
|
|
126
|
+
case 5:
|
|
127
|
+
token = _context.sent;
|
|
128
|
+
if (!(!token && typeof document !== 'undefined')) {
|
|
129
|
+
_context.next = 27;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
// Try to get from raw cookie
|
|
133
|
+
cookies = document.cookie.split(';');
|
|
134
|
+
_iterator = _createForOfIteratorHelper(cookies);
|
|
135
|
+
_context.prev = 9;
|
|
136
|
+
_iterator.s();
|
|
137
|
+
case 11:
|
|
138
|
+
if ((_step = _iterator.n()).done) {
|
|
139
|
+
_context.next = 19;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
cookie = _step.value;
|
|
143
|
+
_cookie$trim$split = cookie.trim().split('='), _cookie$trim$split2 = _slicedToArray(_cookie$trim$split, 2), name = _cookie$trim$split2[0], value = _cookie$trim$split2[1];
|
|
144
|
+
if (!(name === 'authtoken')) {
|
|
145
|
+
_context.next = 17;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
token = decodeURIComponent(value);
|
|
149
|
+
return _context.abrupt("break", 19);
|
|
150
|
+
case 17:
|
|
151
|
+
_context.next = 11;
|
|
152
|
+
break;
|
|
153
|
+
case 19:
|
|
154
|
+
_context.next = 24;
|
|
155
|
+
break;
|
|
156
|
+
case 21:
|
|
157
|
+
_context.prev = 21;
|
|
158
|
+
_context.t0 = _context["catch"](9);
|
|
159
|
+
_iterator.e(_context.t0);
|
|
160
|
+
case 24:
|
|
161
|
+
_context.prev = 24;
|
|
162
|
+
_iterator.f();
|
|
163
|
+
return _context.finish(24);
|
|
164
|
+
case 27:
|
|
165
|
+
if (token) {
|
|
166
|
+
this.authtoken = token;
|
|
167
|
+
this.axios.defaults.headers.common['authtoken'] = token;
|
|
168
|
+
}
|
|
169
|
+
_context.next = 32;
|
|
170
|
+
break;
|
|
171
|
+
case 30:
|
|
172
|
+
_context.prev = 30;
|
|
173
|
+
_context.t1 = _context["catch"](2);
|
|
174
|
+
case 32:
|
|
175
|
+
_context.prev = 32;
|
|
176
|
+
_context.next = 35;
|
|
177
|
+
return this.localStorageAdaptor.getItem('rbtUser');
|
|
178
|
+
case 35:
|
|
179
|
+
cachedUser = _context.sent;
|
|
180
|
+
if (cachedUser) {
|
|
181
|
+
parsed = typeof cachedUser === 'string' ? JSON.parse(cachedUser) : cachedUser;
|
|
182
|
+
if (parsed && parsed.id) {
|
|
183
|
+
this.currentUser = new _rbt_user["default"]({
|
|
184
|
+
id: parsed.id
|
|
185
|
+
}, this.axios);
|
|
186
|
+
this.currentUser.setData(parsed);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
_context.next = 41;
|
|
190
|
+
break;
|
|
191
|
+
case 39:
|
|
192
|
+
_context.prev = 39;
|
|
193
|
+
_context.t2 = _context["catch"](32);
|
|
194
|
+
case 41:
|
|
195
|
+
case "end":
|
|
196
|
+
return _context.stop();
|
|
76
197
|
}
|
|
77
|
-
}
|
|
198
|
+
}, _callee, this, [[2, 30], [9, 21, 24, 27], [32, 39]]);
|
|
199
|
+
}));
|
|
200
|
+
function _initializeFromStorage() {
|
|
201
|
+
return _initializeFromStorage2.apply(this, arguments);
|
|
78
202
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
try {
|
|
88
|
-
// Try to get user from storage adaptor
|
|
89
|
-
const cachedUser = await this.localStorageAdaptor.getItem('rbtUser');
|
|
90
|
-
if (cachedUser) {
|
|
91
|
-
const parsed = typeof cachedUser === 'string' ? JSON.parse(cachedUser) : cachedUser;
|
|
92
|
-
if (parsed && parsed.id) {
|
|
93
|
-
this.currentUser = new RbtUser({
|
|
94
|
-
id: parsed.id
|
|
95
|
-
}, this.axios);
|
|
96
|
-
this.currentUser.setData(parsed);
|
|
97
|
-
console.log('[RbtApi] Loaded user from storage adaptor');
|
|
98
|
-
}
|
|
203
|
+
return _initializeFromStorage;
|
|
204
|
+
}()
|
|
205
|
+
}, {
|
|
206
|
+
key: "getWebSocketClient",
|
|
207
|
+
value: function getWebSocketClient() {
|
|
208
|
+
// Reuse existing WebSocket if it's OPEN or CONNECTING (to prevent race condition)
|
|
209
|
+
if (this.websocketClient && (this.websocketClient.readyState === WebSocket.OPEN || this.websocketClient.readyState === WebSocket.CONNECTING)) {
|
|
210
|
+
return this.websocketClient;
|
|
99
211
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
// Reuse existing WebSocket if it's OPEN or CONNECTING (to prevent race condition)
|
|
106
|
-
if (this.websocketClient && (this.websocketClient.readyState === WebSocket.OPEN || this.websocketClient.readyState === WebSocket.CONNECTING)) {
|
|
212
|
+
var baseUrl = this.axios.defaults.baseURL;
|
|
213
|
+
var wsProtocol = baseUrl.startsWith('https') ? 'wss://' : 'ws://';
|
|
214
|
+
var wsUrl = baseUrl.replace(/^https?:\/\//, wsProtocol);
|
|
215
|
+
this.websocketClient = new WebSocket("".concat(wsUrl, "/realtime"));
|
|
216
|
+
this._setupWebSocketHandlers(this.websocketClient);
|
|
107
217
|
return this.websocketClient;
|
|
108
218
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
219
|
+
}, {
|
|
220
|
+
key: "_setupWebSocketHandlers",
|
|
221
|
+
value: function _setupWebSocketHandlers(ws) {
|
|
222
|
+
var _this = this;
|
|
223
|
+
ws.onopen = function () {
|
|
224
|
+
_this._wsReconnectAttempts = 0;
|
|
225
|
+
_this._wsConnected = true;
|
|
226
|
+
|
|
227
|
+
// Re-subscribe to all objects that were previously subscribed
|
|
228
|
+
if (_this._wsSubscriptions) {
|
|
229
|
+
var _iterator2 = _createForOfIteratorHelper(_this._wsSubscriptions),
|
|
230
|
+
_step2;
|
|
231
|
+
try {
|
|
232
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
233
|
+
var objectId = _step2.value;
|
|
234
|
+
ws.send(JSON.stringify({
|
|
235
|
+
type: 'subscribe',
|
|
236
|
+
objectId: objectId
|
|
237
|
+
}));
|
|
238
|
+
}
|
|
239
|
+
} catch (err) {
|
|
240
|
+
_iterator2.e(err);
|
|
241
|
+
} finally {
|
|
242
|
+
_iterator2.f();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
ws.onclose = function (event) {
|
|
247
|
+
_this._wsConnected = false;
|
|
248
|
+
|
|
249
|
+
// Attempt reconnection with exponential backoff
|
|
250
|
+
if (!_this._wsManualClose && _this._wsReconnectAttempts < 5) {
|
|
251
|
+
var delay = Math.min(1000 * Math.pow(2, _this._wsReconnectAttempts), 30000);
|
|
252
|
+
setTimeout(function () {
|
|
253
|
+
_this._wsReconnectAttempts++;
|
|
254
|
+
_this.websocketClient = null; // Clear the old connection
|
|
255
|
+
_this.getWebSocketClient(); // Create new connection
|
|
256
|
+
}, delay);
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
ws.onerror = function (err) {
|
|
260
|
+
console.error('[RbtApi] WebSocket error:', err);
|
|
261
|
+
_this._wsConnected = false;
|
|
262
|
+
};
|
|
122
263
|
|
|
123
|
-
//
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
ws.
|
|
127
|
-
type: 'subscribe',
|
|
128
|
-
objectId
|
|
129
|
-
}));
|
|
264
|
+
// Handle ping/pong for keep-alive
|
|
265
|
+
ws.addEventListener('ping', function () {
|
|
266
|
+
if (ws.readyState === WebSocket.OPEN) {
|
|
267
|
+
ws.pong();
|
|
130
268
|
}
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
ws.onclose = event => {
|
|
134
|
-
console.warn('[RbtApi] WebSocket closed:', event.code, event.reason);
|
|
135
|
-
this._wsConnected = false;
|
|
269
|
+
});
|
|
136
270
|
|
|
137
|
-
//
|
|
138
|
-
|
|
139
|
-
const delay = Math.min(1000 * Math.pow(2, this._wsReconnectAttempts), 30000);
|
|
140
|
-
console.log(`[RbtApi] Attempting reconnection in ${delay}ms (attempt ${this._wsReconnectAttempts + 1}/5)`);
|
|
141
|
-
setTimeout(() => {
|
|
142
|
-
this._wsReconnectAttempts++;
|
|
143
|
-
this.websocketClient = null; // Clear the old connection
|
|
144
|
-
this.getWebSocketClient(); // Create new connection
|
|
145
|
-
}, delay);
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
ws.onerror = err => {
|
|
149
|
-
console.error('[RbtApi] WebSocket error:', err);
|
|
271
|
+
// Initialize connection tracking
|
|
272
|
+
this._wsReconnectAttempts = this._wsReconnectAttempts || 0;
|
|
150
273
|
this._wsConnected = false;
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
// Handle ping/pong for keep-alive
|
|
154
|
-
ws.addEventListener('ping', () => {
|
|
155
|
-
if (ws.readyState === WebSocket.OPEN) {
|
|
156
|
-
ws.pong();
|
|
157
|
-
}
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
// Initialize connection tracking
|
|
161
|
-
this._wsReconnectAttempts = this._wsReconnectAttempts || 0;
|
|
162
|
-
this._wsConnected = false;
|
|
163
|
-
this._wsManualClose = false;
|
|
164
|
-
this._wsSubscriptions = this._wsSubscriptions || new Set();
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Method to track subscriptions for reconnection
|
|
168
|
-
_trackSubscription(objectId) {
|
|
169
|
-
if (!this._wsSubscriptions) this._wsSubscriptions = new Set();
|
|
170
|
-
this._wsSubscriptions.add(objectId);
|
|
171
|
-
}
|
|
172
|
-
_untrackSubscription(objectId) {
|
|
173
|
-
if (this._wsSubscriptions) {
|
|
174
|
-
this._wsSubscriptions.delete(objectId);
|
|
274
|
+
this._wsManualClose = false;
|
|
275
|
+
this._wsSubscriptions = this._wsSubscriptions || new Set();
|
|
175
276
|
}
|
|
176
|
-
}
|
|
177
277
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
this.
|
|
183
|
-
this.
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
async initAuthToken(authtoken) {
|
|
187
|
-
if (!authtoken && this.localStorageAdaptor) {
|
|
188
|
-
authtoken = await this.localStorageAdaptor.getItem('authtoken');
|
|
189
|
-
}
|
|
190
|
-
if (authtoken) {
|
|
191
|
-
this.authtoken = authtoken;
|
|
192
|
-
this.axios.defaults.headers.common['authtoken'] = this.authtoken;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
async initApiKey(apikey) {
|
|
196
|
-
if (!apikey && this.localStorageAdaptor) {
|
|
197
|
-
apikey = await this.localStorageAdaptor.getItem('apikey');
|
|
198
|
-
}
|
|
199
|
-
if (apikey) {
|
|
200
|
-
this.apikey = apikey;
|
|
201
|
-
this.axios.defaults.headers.common['apikey'] = this.apikey;
|
|
278
|
+
// Method to track subscriptions for reconnection
|
|
279
|
+
}, {
|
|
280
|
+
key: "_trackSubscription",
|
|
281
|
+
value: function _trackSubscription(objectId) {
|
|
282
|
+
if (!this._wsSubscriptions) this._wsSubscriptions = new Set();
|
|
283
|
+
this._wsSubscriptions.add(objectId);
|
|
202
284
|
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
db.createObjectStore('files', {
|
|
209
|
-
autoIncrement: true
|
|
210
|
-
});
|
|
211
|
-
}
|
|
285
|
+
}, {
|
|
286
|
+
key: "_untrackSubscription",
|
|
287
|
+
value: function _untrackSubscription(objectId) {
|
|
288
|
+
if (this._wsSubscriptions) {
|
|
289
|
+
this._wsSubscriptions["delete"](objectId);
|
|
212
290
|
}
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
setAppServiceHost(host) {
|
|
216
|
-
this.appServiceHost = host;
|
|
217
|
-
this.axios.defaults.baseURL = host;
|
|
218
|
-
}
|
|
219
|
-
setSiteEnv(siteEnv) {
|
|
220
|
-
this.siteEnv = siteEnv;
|
|
221
|
-
}
|
|
222
|
-
getSiteEnv(key = null) {
|
|
223
|
-
if (key) {
|
|
224
|
-
return this.siteEnv[key];
|
|
225
|
-
}
|
|
226
|
-
return this.siteEnv;
|
|
227
|
-
}
|
|
228
|
-
async registerTypedefs(typedefs) {
|
|
229
|
-
try {
|
|
230
|
-
const response = await this.axios.post('/api/doctree/registerTypedefs', [{
|
|
231
|
-
typedefs: typedefs
|
|
232
|
-
}]);
|
|
233
|
-
return response.data;
|
|
234
|
-
} catch (e) {
|
|
235
|
-
this._handleError(e);
|
|
236
291
|
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Logs in a user and stores the authToken.
|
|
241
|
-
*
|
|
242
|
-
* @param {Object} params - The login parameters.
|
|
243
|
-
* @param {string} params.email - The email of the user.
|
|
244
|
-
* @param {string} params.password - The password of the user.
|
|
245
|
-
* @param {string} params.code - The password of the user.
|
|
246
|
-
* @returns {Promise<Object>} - The response data from the API.
|
|
247
|
-
*/
|
|
248
|
-
async login(params) {
|
|
249
|
-
try {
|
|
250
|
-
const response = await this.axios.post('/user_service/loginUser', [{
|
|
251
|
-
email: params.email,
|
|
252
|
-
password: params.password ? CryptoJS.MD5(params.password).toString(CryptoJS.enc.Hex) : null,
|
|
253
|
-
// legacy hash password (md5)
|
|
254
|
-
passwd: params.password || null,
|
|
255
|
-
// current password
|
|
256
|
-
code: params.code || null // single-use signon code (password resets)
|
|
257
|
-
}]);
|
|
258
|
-
if (response.data.ok === false) {
|
|
259
|
-
return this._handleError(response);
|
|
260
|
-
}
|
|
261
|
-
this.iac_session = response.data;
|
|
262
|
-
this.currentUser = this.iac_session ? new RbtUser(this.iac_session.user, this.axios) : null;
|
|
263
|
-
// update axios instance headers with authtoken
|
|
264
|
-
this.axios.defaults.headers.common['authtoken'] = response.data.authToken;
|
|
265
|
-
this.authtoken = response.data.authToken;
|
|
266
|
-
if (this.localStorageAdaptor) {
|
|
267
|
-
await this.localStorageAdaptor.setItem('authtoken', response.data.authToken);
|
|
268
|
-
if (this.iac_session?.user) {
|
|
269
|
-
await this.localStorageAdaptor.setItem('rbtUser', JSON.stringify(this.iac_session.user));
|
|
270
|
-
}
|
|
271
292
|
|
|
272
|
-
|
|
293
|
+
// Method to gracefully close WebSocket
|
|
294
|
+
}, {
|
|
295
|
+
key: "closeWebSocket",
|
|
296
|
+
value: function closeWebSocket() {
|
|
297
|
+
if (this.websocketClient) {
|
|
298
|
+
this._wsManualClose = true;
|
|
299
|
+
this.websocketClient.close();
|
|
300
|
+
this.websocketClient = null;
|
|
273
301
|
}
|
|
274
|
-
return response.data;
|
|
275
|
-
} catch (e) {
|
|
276
|
-
this._handleError(e);
|
|
277
302
|
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
303
|
+
}, {
|
|
304
|
+
key: "initAuthToken",
|
|
305
|
+
value: function () {
|
|
306
|
+
var _initAuthToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(authtoken) {
|
|
307
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
308
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
309
|
+
case 0:
|
|
310
|
+
if (!(!authtoken && this.localStorageAdaptor)) {
|
|
311
|
+
_context2.next = 4;
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
_context2.next = 3;
|
|
315
|
+
return this.localStorageAdaptor.getItem('authtoken');
|
|
316
|
+
case 3:
|
|
317
|
+
authtoken = _context2.sent;
|
|
318
|
+
case 4:
|
|
319
|
+
if (authtoken) {
|
|
320
|
+
this.authtoken = authtoken;
|
|
321
|
+
this.axios.defaults.headers.common['authtoken'] = this.authtoken;
|
|
322
|
+
}
|
|
323
|
+
case 5:
|
|
324
|
+
case "end":
|
|
325
|
+
return _context2.stop();
|
|
326
|
+
}
|
|
327
|
+
}, _callee2, this);
|
|
328
|
+
}));
|
|
329
|
+
function initAuthToken(_x) {
|
|
330
|
+
return _initAuthToken.apply(this, arguments);
|
|
331
|
+
}
|
|
332
|
+
return initAuthToken;
|
|
333
|
+
}()
|
|
334
|
+
}, {
|
|
335
|
+
key: "initApiKey",
|
|
336
|
+
value: function () {
|
|
337
|
+
var _initApiKey = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(apikey) {
|
|
338
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
339
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
340
|
+
case 0:
|
|
341
|
+
if (!(!apikey && this.localStorageAdaptor)) {
|
|
342
|
+
_context3.next = 4;
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
_context3.next = 3;
|
|
346
|
+
return this.localStorageAdaptor.getItem('apikey');
|
|
347
|
+
case 3:
|
|
348
|
+
apikey = _context3.sent;
|
|
349
|
+
case 4:
|
|
350
|
+
if (apikey) {
|
|
351
|
+
this.apikey = apikey;
|
|
352
|
+
this.axios.defaults.headers.common['apikey'] = this.apikey;
|
|
353
|
+
}
|
|
354
|
+
case 5:
|
|
355
|
+
case "end":
|
|
356
|
+
return _context3.stop();
|
|
357
|
+
}
|
|
358
|
+
}, _callee3, this);
|
|
359
|
+
}));
|
|
360
|
+
function initApiKey(_x2) {
|
|
361
|
+
return _initApiKey.apply(this, arguments);
|
|
284
362
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
363
|
+
return initApiKey;
|
|
364
|
+
}()
|
|
365
|
+
}, {
|
|
366
|
+
key: "initLocalDb",
|
|
367
|
+
value: function () {
|
|
368
|
+
var _initLocalDb = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
369
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
370
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
371
|
+
case 0:
|
|
372
|
+
_context4.next = 2;
|
|
373
|
+
return (0, _idb.openDB)('RBTFileDatabase', 1, {
|
|
374
|
+
upgrade: function upgrade(db) {
|
|
375
|
+
if (!db.objectStoreNames.contains('files')) {
|
|
376
|
+
db.createObjectStore('files', {
|
|
377
|
+
autoIncrement: true
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
case 2:
|
|
383
|
+
this.localDb = _context4.sent;
|
|
384
|
+
case 3:
|
|
385
|
+
case "end":
|
|
386
|
+
return _context4.stop();
|
|
387
|
+
}
|
|
388
|
+
}, _callee4, this);
|
|
389
|
+
}));
|
|
390
|
+
function initLocalDb() {
|
|
391
|
+
return _initLocalDb.apply(this, arguments);
|
|
292
392
|
}
|
|
293
|
-
return
|
|
294
|
-
}
|
|
295
|
-
|
|
393
|
+
return initLocalDb;
|
|
394
|
+
}()
|
|
395
|
+
}, {
|
|
396
|
+
key: "setAppServiceHost",
|
|
397
|
+
value: function setAppServiceHost(host) {
|
|
398
|
+
this.appServiceHost = host;
|
|
399
|
+
this.axios.defaults.baseURL = host;
|
|
296
400
|
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
401
|
+
}, {
|
|
402
|
+
key: "setSiteEnv",
|
|
403
|
+
value: function setSiteEnv(siteEnv) {
|
|
404
|
+
this.siteEnv = siteEnv;
|
|
405
|
+
}
|
|
406
|
+
}, {
|
|
407
|
+
key: "getSiteEnv",
|
|
408
|
+
value: function getSiteEnv() {
|
|
409
|
+
var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
410
|
+
if (key) {
|
|
411
|
+
return this.siteEnv[key];
|
|
305
412
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
413
|
+
return this.siteEnv;
|
|
414
|
+
}
|
|
415
|
+
}, {
|
|
416
|
+
key: "registerTypedefs",
|
|
417
|
+
value: function () {
|
|
418
|
+
var _registerTypedefs = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(typedefs) {
|
|
419
|
+
var response;
|
|
420
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
421
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
422
|
+
case 0:
|
|
423
|
+
_context5.prev = 0;
|
|
424
|
+
_context5.next = 3;
|
|
425
|
+
return this.axios.post('/api/doctree/registerTypedefs', [{
|
|
426
|
+
typedefs: typedefs
|
|
427
|
+
}]);
|
|
428
|
+
case 3:
|
|
429
|
+
response = _context5.sent;
|
|
430
|
+
return _context5.abrupt("return", response.data);
|
|
431
|
+
case 7:
|
|
432
|
+
_context5.prev = 7;
|
|
433
|
+
_context5.t0 = _context5["catch"](0);
|
|
434
|
+
this._handleError(_context5.t0);
|
|
435
|
+
case 10:
|
|
436
|
+
case "end":
|
|
437
|
+
return _context5.stop();
|
|
438
|
+
}
|
|
439
|
+
}, _callee5, this, [[0, 7]]);
|
|
440
|
+
}));
|
|
441
|
+
function registerTypedefs(_x3) {
|
|
442
|
+
return _registerTypedefs.apply(this, arguments);
|
|
313
443
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
444
|
+
return registerTypedefs;
|
|
445
|
+
}()
|
|
446
|
+
/**
|
|
447
|
+
* Logs in a user and stores the authToken.
|
|
448
|
+
*
|
|
449
|
+
* @param {Object} params - The login parameters.
|
|
450
|
+
* @param {string} params.email - The email of the user.
|
|
451
|
+
* @param {string} params.password - The password of the user.
|
|
452
|
+
* @param {string} params.code - The password of the user.
|
|
453
|
+
* @returns {Promise<Object>} - The response data from the API.
|
|
454
|
+
*/
|
|
455
|
+
}, {
|
|
456
|
+
key: "login",
|
|
457
|
+
value: (function () {
|
|
458
|
+
var _login = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(params) {
|
|
459
|
+
var response, _this$iac_session;
|
|
460
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
461
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
462
|
+
case 0:
|
|
463
|
+
_context6.prev = 0;
|
|
464
|
+
_context6.next = 3;
|
|
465
|
+
return this.axios.post('/user_service/loginUser', [{
|
|
466
|
+
email: params.email,
|
|
467
|
+
password: params.password ? _cryptoJs["default"].MD5(params.password).toString(_cryptoJs["default"].enc.Hex) : null,
|
|
468
|
+
// legacy hash password (md5)
|
|
469
|
+
passwd: params.password || null,
|
|
470
|
+
// current password
|
|
471
|
+
code: params.code || null // single-use signon code (password resets)
|
|
472
|
+
}]);
|
|
473
|
+
case 3:
|
|
474
|
+
response = _context6.sent;
|
|
475
|
+
if (!(response.data.ok === false)) {
|
|
476
|
+
_context6.next = 6;
|
|
477
|
+
break;
|
|
478
|
+
}
|
|
479
|
+
return _context6.abrupt("return", this._handleError(response));
|
|
480
|
+
case 6:
|
|
481
|
+
this.iac_session = response.data;
|
|
482
|
+
this.currentUser = this.iac_session ? new _rbt_user["default"](this.iac_session.user, this.axios) : null;
|
|
483
|
+
// update axios instance headers with authtoken
|
|
484
|
+
this.axios.defaults.headers.common['authtoken'] = response.data.authToken;
|
|
485
|
+
this.authtoken = response.data.authToken;
|
|
486
|
+
if (!this.localStorageAdaptor) {
|
|
487
|
+
_context6.next = 16;
|
|
488
|
+
break;
|
|
489
|
+
}
|
|
490
|
+
_context6.next = 13;
|
|
491
|
+
return this.localStorageAdaptor.setItem('authtoken', response.data.authToken);
|
|
492
|
+
case 13:
|
|
493
|
+
if (!((_this$iac_session = this.iac_session) !== null && _this$iac_session !== void 0 && _this$iac_session.user)) {
|
|
494
|
+
_context6.next = 16;
|
|
495
|
+
break;
|
|
496
|
+
}
|
|
497
|
+
_context6.next = 16;
|
|
498
|
+
return this.localStorageAdaptor.setItem('rbtUser', JSON.stringify(this.iac_session.user));
|
|
499
|
+
case 16:
|
|
500
|
+
return _context6.abrupt("return", response.data);
|
|
501
|
+
case 19:
|
|
502
|
+
_context6.prev = 19;
|
|
503
|
+
_context6.t0 = _context6["catch"](0);
|
|
504
|
+
this._handleError(_context6.t0);
|
|
505
|
+
case 22:
|
|
506
|
+
case "end":
|
|
507
|
+
return _context6.stop();
|
|
508
|
+
}
|
|
509
|
+
}, _callee6, this, [[0, 19]]);
|
|
510
|
+
}));
|
|
511
|
+
function login(_x4) {
|
|
512
|
+
return _login.apply(this, arguments);
|
|
318
513
|
}
|
|
514
|
+
return login;
|
|
515
|
+
}())
|
|
516
|
+
}, {
|
|
517
|
+
key: "loginWithOauth",
|
|
518
|
+
value: function () {
|
|
519
|
+
var _loginWithOauth = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(userData) {
|
|
520
|
+
var response;
|
|
521
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
522
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
523
|
+
case 0:
|
|
524
|
+
_context7.prev = 0;
|
|
525
|
+
_context7.next = 3;
|
|
526
|
+
return this.post('/api/account/registerOrSigninOauth', userData);
|
|
527
|
+
case 3:
|
|
528
|
+
response = _context7.sent;
|
|
529
|
+
if (!(response.ok === false)) {
|
|
530
|
+
_context7.next = 6;
|
|
531
|
+
break;
|
|
532
|
+
}
|
|
533
|
+
return _context7.abrupt("return", this._handleError(response));
|
|
534
|
+
case 6:
|
|
535
|
+
this.iac_session = response;
|
|
536
|
+
this.currentUser = this.iac_session ? new _rbt_user["default"](this.iac_session.user, this.axios) : null;
|
|
537
|
+
// update axios instance headers with authtoken
|
|
538
|
+
this.axios.defaults.headers.common['authtoken'] = response.authToken;
|
|
539
|
+
this.authtoken = response.authToken;
|
|
540
|
+
if (!this.localStorageAdaptor) {
|
|
541
|
+
_context7.next = 13;
|
|
542
|
+
break;
|
|
543
|
+
}
|
|
544
|
+
_context7.next = 13;
|
|
545
|
+
return this.localStorageAdaptor.setItem('authtoken', response.authToken);
|
|
546
|
+
case 13:
|
|
547
|
+
return _context7.abrupt("return", response);
|
|
548
|
+
case 16:
|
|
549
|
+
_context7.prev = 16;
|
|
550
|
+
_context7.t0 = _context7["catch"](0);
|
|
551
|
+
this._handleError(_context7.t0);
|
|
552
|
+
case 19:
|
|
553
|
+
case "end":
|
|
554
|
+
return _context7.stop();
|
|
555
|
+
}
|
|
556
|
+
}, _callee7, this, [[0, 16]]);
|
|
557
|
+
}));
|
|
558
|
+
function loginWithOauth(_x5) {
|
|
559
|
+
return _loginWithOauth.apply(this, arguments);
|
|
560
|
+
}
|
|
561
|
+
return loginWithOauth;
|
|
562
|
+
}()
|
|
563
|
+
}, {
|
|
564
|
+
key: "logout",
|
|
565
|
+
value: function () {
|
|
566
|
+
var _logout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
|
|
567
|
+
var response;
|
|
568
|
+
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
|
|
569
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
570
|
+
case 0:
|
|
571
|
+
_context8.prev = 0;
|
|
572
|
+
_context8.next = 3;
|
|
573
|
+
return this.axios.post('/user_service/logoutUser');
|
|
574
|
+
case 3:
|
|
575
|
+
response = _context8.sent;
|
|
576
|
+
if (!(response.data.ok === false)) {
|
|
577
|
+
_context8.next = 6;
|
|
578
|
+
break;
|
|
579
|
+
}
|
|
580
|
+
return _context8.abrupt("return", this._handleError(response));
|
|
581
|
+
case 6:
|
|
582
|
+
// Clear the iac_session and remove the auth token from axios headers
|
|
583
|
+
this.iac_session = null;
|
|
584
|
+
this.currentUser = null;
|
|
585
|
+
this.authtoken = null;
|
|
586
|
+
if (this.axios.defaults.headers.common['authtoken']) {
|
|
587
|
+
delete this.axios.defaults.headers.common['authtoken'];
|
|
588
|
+
}
|
|
319
589
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
590
|
+
// Clear localStorage if it's being used
|
|
591
|
+
if (!this.localStorageAdaptor) {
|
|
592
|
+
_context8.next = 13;
|
|
593
|
+
break;
|
|
594
|
+
}
|
|
595
|
+
_context8.next = 13;
|
|
596
|
+
return this.localStorageAdaptor.removeItem('authtoken');
|
|
597
|
+
case 13:
|
|
598
|
+
return _context8.abrupt("return", response.data);
|
|
599
|
+
case 16:
|
|
600
|
+
_context8.prev = 16;
|
|
601
|
+
_context8.t0 = _context8["catch"](0);
|
|
602
|
+
this._handleError(_context8.t0);
|
|
603
|
+
case 19:
|
|
604
|
+
case "end":
|
|
605
|
+
return _context8.stop();
|
|
606
|
+
}
|
|
607
|
+
}, _callee8, this, [[0, 16]]);
|
|
608
|
+
}));
|
|
609
|
+
function logout() {
|
|
610
|
+
return _logout.apply(this, arguments);
|
|
335
611
|
}
|
|
612
|
+
return logout;
|
|
613
|
+
}()
|
|
614
|
+
}, {
|
|
615
|
+
key: "getCurrentUser",
|
|
616
|
+
value: function getCurrentUser() {
|
|
336
617
|
if (this.currentUser) {
|
|
337
618
|
return this.currentUser;
|
|
338
619
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
620
|
+
}
|
|
621
|
+
}, {
|
|
622
|
+
key: "loadCurrentUser",
|
|
623
|
+
value: function () {
|
|
624
|
+
var _loadCurrentUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
|
|
625
|
+
var _this2 = this;
|
|
626
|
+
var result;
|
|
627
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
628
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
629
|
+
case 0:
|
|
630
|
+
_context10.prev = 0;
|
|
631
|
+
if (!this._loadCurrentUserPromise) {
|
|
632
|
+
_context10.next = 3;
|
|
633
|
+
break;
|
|
634
|
+
}
|
|
635
|
+
return _context10.abrupt("return", this._loadCurrentUserPromise);
|
|
636
|
+
case 3:
|
|
637
|
+
if (!this.currentUser) {
|
|
638
|
+
_context10.next = 5;
|
|
639
|
+
break;
|
|
640
|
+
}
|
|
641
|
+
return _context10.abrupt("return", this.currentUser);
|
|
642
|
+
case 5:
|
|
643
|
+
if (!this.apikey) {
|
|
644
|
+
_context10.next = 9;
|
|
645
|
+
break;
|
|
646
|
+
}
|
|
647
|
+
return _context10.abrupt("return", null);
|
|
648
|
+
case 9:
|
|
649
|
+
if (!this.authtoken) {
|
|
650
|
+
_context10.next = 18;
|
|
651
|
+
break;
|
|
652
|
+
}
|
|
653
|
+
this._loadCurrentUserPromise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
|
|
654
|
+
var response, _response$user;
|
|
655
|
+
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
|
|
656
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
657
|
+
case 0:
|
|
658
|
+
_context9.next = 2;
|
|
659
|
+
return _this2.refreshAuthToken(_this2.authtoken);
|
|
660
|
+
case 2:
|
|
661
|
+
response = _context9.sent;
|
|
662
|
+
if (response) {
|
|
663
|
+
_context9.next = 5;
|
|
664
|
+
break;
|
|
665
|
+
}
|
|
666
|
+
return _context9.abrupt("return", null);
|
|
667
|
+
case 5:
|
|
668
|
+
if (!(response !== null && response !== void 0 && response.user)) {
|
|
669
|
+
_context9.next = 11;
|
|
670
|
+
break;
|
|
671
|
+
}
|
|
672
|
+
_this2.currentUser = new _rbt_user["default"]({
|
|
673
|
+
id: response === null || response === void 0 || (_response$user = response.user) === null || _response$user === void 0 ? void 0 : _response$user.id
|
|
674
|
+
}, _this2.axios);
|
|
675
|
+
_this2.currentUser.setData(response.user);
|
|
676
|
+
if (!_this2.localStorageAdaptor) {
|
|
677
|
+
_context9.next = 11;
|
|
678
|
+
break;
|
|
679
|
+
}
|
|
680
|
+
_context9.next = 11;
|
|
681
|
+
return _this2.localStorageAdaptor.setItem('rbtUser', JSON.stringify(response.user));
|
|
682
|
+
case 11:
|
|
683
|
+
return _context9.abrupt("return", _this2.currentUser);
|
|
684
|
+
case 12:
|
|
685
|
+
case "end":
|
|
686
|
+
return _context9.stop();
|
|
687
|
+
}
|
|
688
|
+
}, _callee9);
|
|
689
|
+
}))();
|
|
690
|
+
_context10.next = 13;
|
|
691
|
+
return this._loadCurrentUserPromise;
|
|
692
|
+
case 13:
|
|
693
|
+
result = _context10.sent;
|
|
694
|
+
this._loadCurrentUserPromise = null;
|
|
695
|
+
return _context10.abrupt("return", result);
|
|
696
|
+
case 18:
|
|
697
|
+
this.currentUser = null;
|
|
698
|
+
case 19:
|
|
699
|
+
return _context10.abrupt("return", null);
|
|
700
|
+
case 22:
|
|
701
|
+
_context10.prev = 22;
|
|
702
|
+
_context10.t0 = _context10["catch"](0);
|
|
703
|
+
return _context10.abrupt("return", this._handleError(_context10.t0));
|
|
704
|
+
case 25:
|
|
705
|
+
case "end":
|
|
706
|
+
return _context10.stop();
|
|
354
707
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
this
|
|
359
|
-
return result;
|
|
360
|
-
//this.currentOrg = new RbtObject(response.organization, this.axios);
|
|
361
|
-
//this.currentOrg.type = '<@iac.organization>';
|
|
362
|
-
} else {
|
|
363
|
-
this.currentUser = null;
|
|
708
|
+
}, _callee10, this, [[0, 22]]);
|
|
709
|
+
}));
|
|
710
|
+
function loadCurrentUser() {
|
|
711
|
+
return _loadCurrentUser.apply(this, arguments);
|
|
364
712
|
}
|
|
365
|
-
return
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
713
|
+
return loadCurrentUser;
|
|
714
|
+
}()
|
|
715
|
+
}, {
|
|
716
|
+
key: "confirmUserEmail",
|
|
717
|
+
value: function () {
|
|
718
|
+
var _confirmUserEmail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(confirmCode) {
|
|
719
|
+
var params, response;
|
|
720
|
+
return _regeneratorRuntime().wrap(function _callee11$(_context11) {
|
|
721
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
722
|
+
case 0:
|
|
723
|
+
params = {
|
|
724
|
+
emailConfirmCode: confirmCode
|
|
725
|
+
};
|
|
726
|
+
_context11.prev = 1;
|
|
727
|
+
_context11.next = 4;
|
|
728
|
+
return this.axios.post('/user_service/confirmUserEmail', [params]);
|
|
729
|
+
case 4:
|
|
730
|
+
response = _context11.sent;
|
|
731
|
+
if (!(response.data.ok === false)) {
|
|
732
|
+
_context11.next = 7;
|
|
733
|
+
break;
|
|
734
|
+
}
|
|
735
|
+
return _context11.abrupt("return", this._handleError(response));
|
|
736
|
+
case 7:
|
|
737
|
+
return _context11.abrupt("return", response.data);
|
|
738
|
+
case 10:
|
|
739
|
+
_context11.prev = 10;
|
|
740
|
+
_context11.t0 = _context11["catch"](1);
|
|
741
|
+
return _context11.abrupt("return", this._handleError(_context11.t0));
|
|
742
|
+
case 13:
|
|
743
|
+
case "end":
|
|
744
|
+
return _context11.stop();
|
|
745
|
+
}
|
|
746
|
+
}, _callee11, this, [[1, 10]]);
|
|
747
|
+
}));
|
|
748
|
+
function confirmUserEmail(_x6) {
|
|
749
|
+
return _confirmUserEmail.apply(this, arguments);
|
|
378
750
|
}
|
|
379
|
-
return
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
751
|
+
return confirmUserEmail;
|
|
752
|
+
}()
|
|
753
|
+
}, {
|
|
754
|
+
key: "loadCurrentUserExtended",
|
|
755
|
+
value: function () {
|
|
756
|
+
var _loadCurrentUserExtended = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
|
|
757
|
+
var _this3 = this;
|
|
758
|
+
return _regeneratorRuntime().wrap(function _callee13$(_context13) {
|
|
759
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
760
|
+
case 0:
|
|
761
|
+
if (!this._loadCurrentUserExtendedPromise) {
|
|
762
|
+
_context13.next = 2;
|
|
763
|
+
break;
|
|
764
|
+
}
|
|
765
|
+
return _context13.abrupt("return", this._loadCurrentUserExtendedPromise);
|
|
766
|
+
case 2:
|
|
767
|
+
this._loadCurrentUserExtendedPromise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
|
|
768
|
+
var currentUser;
|
|
769
|
+
return _regeneratorRuntime().wrap(function _callee12$(_context12) {
|
|
770
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
771
|
+
case 0:
|
|
772
|
+
_context12.next = 2;
|
|
773
|
+
return _this3.loadCurrentUser();
|
|
774
|
+
case 2:
|
|
775
|
+
currentUser = _context12.sent;
|
|
776
|
+
if (!currentUser) {
|
|
777
|
+
_context12.next = 7;
|
|
778
|
+
break;
|
|
779
|
+
}
|
|
780
|
+
return _context12.abrupt("return", _this3.loadUser(currentUser.id));
|
|
781
|
+
case 7:
|
|
782
|
+
return _context12.abrupt("return", null);
|
|
783
|
+
case 8:
|
|
784
|
+
case "end":
|
|
785
|
+
return _context12.stop();
|
|
786
|
+
}
|
|
787
|
+
}, _callee12);
|
|
788
|
+
}))();
|
|
789
|
+
_context13.prev = 3;
|
|
790
|
+
_context13.next = 6;
|
|
791
|
+
return this._loadCurrentUserExtendedPromise;
|
|
792
|
+
case 6:
|
|
793
|
+
return _context13.abrupt("return", _context13.sent);
|
|
794
|
+
case 7:
|
|
795
|
+
_context13.prev = 7;
|
|
796
|
+
this._loadCurrentUserExtendedPromise = null;
|
|
797
|
+
return _context13.finish(7);
|
|
798
|
+
case 10:
|
|
799
|
+
case "end":
|
|
800
|
+
return _context13.stop();
|
|
801
|
+
}
|
|
802
|
+
}, _callee13, this, [[3,, 7, 10]]);
|
|
803
|
+
}));
|
|
804
|
+
function loadCurrentUserExtended() {
|
|
805
|
+
return _loadCurrentUserExtended.apply(this, arguments);
|
|
394
806
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
// async refreshAuthToken(authtoken){
|
|
465
|
-
//
|
|
466
|
-
// if(!this.appServiceHost){
|
|
467
|
-
// console.warn('appServiceHost not initialized');
|
|
468
|
-
// return false;
|
|
469
|
-
// }
|
|
470
|
-
//
|
|
471
|
-
// try {
|
|
472
|
-
//
|
|
473
|
-
// const response = await this.axios.post('/user_service/refreshAuthToken', [authtoken]);
|
|
474
|
-
// return response.data;
|
|
475
|
-
//
|
|
476
|
-
// } catch (e) {
|
|
477
|
-
//
|
|
478
|
-
// this._handleError(e);
|
|
479
|
-
// }
|
|
480
|
-
// }
|
|
481
|
-
|
|
482
|
-
/**
|
|
483
|
-
* Registers a new user.
|
|
484
|
-
*
|
|
485
|
-
* @param {Object} dataHash - The data for the new user.
|
|
486
|
-
* @returns {Promise<RbtObject>} - The newly created user as an RbtObject.
|
|
487
|
-
*
|
|
488
|
-
*/
|
|
489
|
-
async registerUser(dataHash = {}) {
|
|
490
|
-
try {
|
|
491
|
-
const response = await this.axios.post('/user_service/registerUser', [dataHash]);
|
|
492
|
-
const record = response.data;
|
|
493
|
-
return new RbtUser(record, this.axios);
|
|
494
|
-
} catch (e) {
|
|
495
|
-
return this._handleError(e);
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* Creates a new file in the system.
|
|
501
|
-
*
|
|
502
|
-
* @param {Object} dataHash - The data for the new file.
|
|
503
|
-
* @returns {Promise<RbtFile>} - The newly created file as an RbtFile.
|
|
504
|
-
*
|
|
505
|
-
*/
|
|
506
|
-
async createFile(dataHash) {
|
|
507
|
-
//return this.create('<@filekit.file>', dataHash);
|
|
508
|
-
try {
|
|
509
|
-
const response = await this.axios.post('/object_service/createObject', ['<@filekit.file>', dataHash]);
|
|
510
|
-
const record = response.data;
|
|
511
|
-
if (dataHash) {
|
|
512
|
-
record.data = dataHash;
|
|
807
|
+
return loadCurrentUserExtended;
|
|
808
|
+
}()
|
|
809
|
+
}, {
|
|
810
|
+
key: "loadUser",
|
|
811
|
+
value: function () {
|
|
812
|
+
var _loadUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(userId) {
|
|
813
|
+
var _this4 = this;
|
|
814
|
+
var params, cacheKey, now, existing, p;
|
|
815
|
+
return _regeneratorRuntime().wrap(function _callee15$(_context15) {
|
|
816
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
817
|
+
case 0:
|
|
818
|
+
params = {
|
|
819
|
+
id: userId
|
|
820
|
+
};
|
|
821
|
+
cacheKey = "loadUser:".concat(userId);
|
|
822
|
+
now = Date.now();
|
|
823
|
+
existing = this.requestCache[cacheKey];
|
|
824
|
+
if (!(existing && now - existing.time < 10000)) {
|
|
825
|
+
_context15.next = 6;
|
|
826
|
+
break;
|
|
827
|
+
}
|
|
828
|
+
return _context15.abrupt("return", existing.val);
|
|
829
|
+
case 6:
|
|
830
|
+
_context15.prev = 6;
|
|
831
|
+
p = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
|
|
832
|
+
var _response$data;
|
|
833
|
+
var response, userData, User;
|
|
834
|
+
return _regeneratorRuntime().wrap(function _callee14$(_context14) {
|
|
835
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
836
|
+
case 0:
|
|
837
|
+
_context14.next = 2;
|
|
838
|
+
return _this4.axios.post('/user_service/loadUser', [params]);
|
|
839
|
+
case 2:
|
|
840
|
+
response = _context14.sent;
|
|
841
|
+
userData = response === null || response === void 0 || (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.user;
|
|
842
|
+
User = new _rbt_user["default"]({
|
|
843
|
+
id: userData.id
|
|
844
|
+
}, _this4.axios);
|
|
845
|
+
User.setData(userData);
|
|
846
|
+
return _context14.abrupt("return", User);
|
|
847
|
+
case 7:
|
|
848
|
+
case "end":
|
|
849
|
+
return _context14.stop();
|
|
850
|
+
}
|
|
851
|
+
}, _callee14);
|
|
852
|
+
}))();
|
|
853
|
+
this.requestCache[cacheKey] = {
|
|
854
|
+
val: p,
|
|
855
|
+
time: now
|
|
856
|
+
};
|
|
857
|
+
_context15.next = 11;
|
|
858
|
+
return p;
|
|
859
|
+
case 11:
|
|
860
|
+
return _context15.abrupt("return", _context15.sent);
|
|
861
|
+
case 14:
|
|
862
|
+
_context15.prev = 14;
|
|
863
|
+
_context15.t0 = _context15["catch"](6);
|
|
864
|
+
return _context15.abrupt("return", this._handleError(_context15.t0));
|
|
865
|
+
case 17:
|
|
866
|
+
case "end":
|
|
867
|
+
return _context15.stop();
|
|
868
|
+
}
|
|
869
|
+
}, _callee15, this, [[6, 14]]);
|
|
870
|
+
}));
|
|
871
|
+
function loadUser(_x7) {
|
|
872
|
+
return _loadUser.apply(this, arguments);
|
|
513
873
|
}
|
|
514
|
-
return
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
874
|
+
return loadUser;
|
|
875
|
+
}()
|
|
876
|
+
}, {
|
|
877
|
+
key: "refreshAuthToken",
|
|
878
|
+
value: function () {
|
|
879
|
+
var _refreshAuthToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(authtoken) {
|
|
880
|
+
var promise, response;
|
|
881
|
+
return _regeneratorRuntime().wrap(function _callee16$(_context16) {
|
|
882
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
883
|
+
case 0:
|
|
884
|
+
if (this.appServiceHost) {
|
|
885
|
+
_context16.next = 2;
|
|
886
|
+
break;
|
|
887
|
+
}
|
|
888
|
+
return _context16.abrupt("return", false);
|
|
889
|
+
case 2:
|
|
890
|
+
if (!this.requestCache[authtoken]) {
|
|
891
|
+
_context16.next = 4;
|
|
892
|
+
break;
|
|
893
|
+
}
|
|
894
|
+
return _context16.abrupt("return", this.requestCache[authtoken]);
|
|
895
|
+
case 4:
|
|
896
|
+
_context16.prev = 4;
|
|
897
|
+
//console.log('RBTTOK Req', authtoken);
|
|
898
|
+
// Create a new promise for the token refresh and store it in the cache
|
|
899
|
+
promise = this.axios.post('/user_service/refreshAuthToken', [authtoken]);
|
|
900
|
+
this.requestCache[authtoken] = promise;
|
|
901
|
+
|
|
902
|
+
// Await the promise to get the response
|
|
903
|
+
_context16.next = 9;
|
|
904
|
+
return promise;
|
|
905
|
+
case 9:
|
|
906
|
+
response = _context16.sent;
|
|
907
|
+
//console.log('RBTTOK Response ',response);
|
|
908
|
+
// Once the promise resolves, delete it from the cache to allow future refreshes
|
|
909
|
+
delete this.requestCache[authtoken];
|
|
910
|
+
|
|
911
|
+
// Return the response data
|
|
912
|
+
return _context16.abrupt("return", response.data);
|
|
913
|
+
case 14:
|
|
914
|
+
_context16.prev = 14;
|
|
915
|
+
_context16.t0 = _context16["catch"](4);
|
|
916
|
+
// On error, remove the cached promise to allow retries
|
|
917
|
+
delete this.requestCache[authtoken];
|
|
918
|
+
this._handleError(_context16.t0);
|
|
919
|
+
case 18:
|
|
920
|
+
case "end":
|
|
921
|
+
return _context16.stop();
|
|
922
|
+
}
|
|
923
|
+
}, _callee16, this, [[4, 14]]);
|
|
924
|
+
}));
|
|
925
|
+
function refreshAuthToken(_x8) {
|
|
926
|
+
return _refreshAuthToken.apply(this, arguments);
|
|
525
927
|
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
928
|
+
return refreshAuthToken;
|
|
929
|
+
}() // async refreshAuthToken(authtoken){
|
|
930
|
+
//
|
|
931
|
+
// if(!this.appServiceHost){
|
|
932
|
+
// console.warn('appServiceHost not initialized');
|
|
933
|
+
// return false;
|
|
934
|
+
// }
|
|
935
|
+
//
|
|
936
|
+
// try {
|
|
937
|
+
//
|
|
938
|
+
// const response = await this.axios.post('/user_service/refreshAuthToken', [authtoken]);
|
|
939
|
+
// return response.data;
|
|
940
|
+
//
|
|
941
|
+
// } catch (e) {
|
|
942
|
+
//
|
|
943
|
+
// this._handleError(e);
|
|
944
|
+
// }
|
|
945
|
+
// }
|
|
946
|
+
/**
|
|
947
|
+
* Registers a new user.
|
|
948
|
+
*
|
|
949
|
+
* @param {Object} dataHash - The data for the new user.
|
|
950
|
+
* @returns {Promise<RbtObject>} - The newly created user as an RbtObject.
|
|
951
|
+
*
|
|
952
|
+
*/
|
|
953
|
+
}, {
|
|
954
|
+
key: "registerUser",
|
|
955
|
+
value: function () {
|
|
956
|
+
var _registerUser = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
|
|
957
|
+
var dataHash,
|
|
958
|
+
response,
|
|
959
|
+
record,
|
|
960
|
+
_args17 = arguments;
|
|
961
|
+
return _regeneratorRuntime().wrap(function _callee17$(_context17) {
|
|
962
|
+
while (1) switch (_context17.prev = _context17.next) {
|
|
963
|
+
case 0:
|
|
964
|
+
dataHash = _args17.length > 0 && _args17[0] !== undefined ? _args17[0] : {};
|
|
965
|
+
_context17.prev = 1;
|
|
966
|
+
_context17.next = 4;
|
|
967
|
+
return this.axios.post('/user_service/registerUser', [dataHash]);
|
|
968
|
+
case 4:
|
|
969
|
+
response = _context17.sent;
|
|
970
|
+
record = response.data;
|
|
971
|
+
return _context17.abrupt("return", new _rbt_user["default"](record, this.axios));
|
|
972
|
+
case 9:
|
|
973
|
+
_context17.prev = 9;
|
|
974
|
+
_context17.t0 = _context17["catch"](1);
|
|
975
|
+
return _context17.abrupt("return", this._handleError(_context17.t0));
|
|
976
|
+
case 12:
|
|
977
|
+
case "end":
|
|
978
|
+
return _context17.stop();
|
|
979
|
+
}
|
|
980
|
+
}, _callee17, this, [[1, 9]]);
|
|
981
|
+
}));
|
|
982
|
+
function registerUser() {
|
|
983
|
+
return _registerUser.apply(this, arguments);
|
|
538
984
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
985
|
+
return registerUser;
|
|
986
|
+
}()
|
|
987
|
+
/**
|
|
988
|
+
* Creates a new file in the system.
|
|
989
|
+
*
|
|
990
|
+
* @param {Object} dataHash - The data for the new file.
|
|
991
|
+
* @returns {Promise<RbtFile>} - The newly created file as an RbtFile.
|
|
992
|
+
*
|
|
993
|
+
*/
|
|
994
|
+
}, {
|
|
995
|
+
key: "createFile",
|
|
996
|
+
value: (function () {
|
|
997
|
+
var _createFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(dataHash) {
|
|
998
|
+
var response, record;
|
|
999
|
+
return _regeneratorRuntime().wrap(function _callee18$(_context18) {
|
|
1000
|
+
while (1) switch (_context18.prev = _context18.next) {
|
|
1001
|
+
case 0:
|
|
1002
|
+
_context18.prev = 0;
|
|
1003
|
+
_context18.next = 3;
|
|
1004
|
+
return this.axios.post('/object_service/createObject', ['<@filekit.file>', dataHash]);
|
|
1005
|
+
case 3:
|
|
1006
|
+
response = _context18.sent;
|
|
1007
|
+
record = response.data;
|
|
1008
|
+
if (dataHash) {
|
|
1009
|
+
record.data = dataHash;
|
|
1010
|
+
}
|
|
1011
|
+
return _context18.abrupt("return", new _rbt_file["default"](record, this.axios, this.localDb));
|
|
1012
|
+
case 9:
|
|
1013
|
+
_context18.prev = 9;
|
|
1014
|
+
_context18.t0 = _context18["catch"](0);
|
|
1015
|
+
return _context18.abrupt("return", this._handleError(_context18.t0));
|
|
1016
|
+
case 12:
|
|
1017
|
+
case "end":
|
|
1018
|
+
return _context18.stop();
|
|
1019
|
+
}
|
|
1020
|
+
}, _callee18, this, [[0, 9]]);
|
|
1021
|
+
}));
|
|
1022
|
+
function createFile(_x9) {
|
|
1023
|
+
return _createFile.apply(this, arguments);
|
|
565
1024
|
}
|
|
566
|
-
return
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
* orderBy: { column: 'timeCreated', direction: 'DESC' },
|
|
602
|
-
* limit: { offset: 0, results: 50 },
|
|
603
|
-
* requestAttrs: ['id', 'configs.title'],
|
|
604
|
-
* excludeAttrs: ['details.log'],
|
|
605
|
-
* resolveReferences: ['translatableContent']
|
|
606
|
-
* });
|
|
607
|
-
*
|
|
608
|
-
* Note: A default orderBy is applied if none is provided, ordering items by 'timeCreated' in descending order.
|
|
609
|
-
*/
|
|
610
|
-
|
|
611
|
-
async query(type, params = {}) {
|
|
612
|
-
let paramsKey;
|
|
613
|
-
try {
|
|
614
|
-
//console.log('RBTAPI.query INIT', type, params);
|
|
615
|
-
|
|
616
|
-
// Validate parameters - reject invalid parameter names
|
|
617
|
-
const validParams = ['type', 'where', 'orderBy', 'limit', 'resolveReferences', 'requestAttrs', 'excludeAttrs', 'timeout', 'enableRealtime'];
|
|
618
|
-
const invalidParams = Object.keys(params).filter(key => !validParams.includes(key));
|
|
619
|
-
if (invalidParams.length > 0) {
|
|
620
|
-
throw new Error(`Invalid query parameter(s): ${invalidParams.join(', ')}. Valid parameters are: ${validParams.join(', ')}`);
|
|
1025
|
+
return createFile;
|
|
1026
|
+
}())
|
|
1027
|
+
}, {
|
|
1028
|
+
key: "loadFile",
|
|
1029
|
+
value: function () {
|
|
1030
|
+
var _loadFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(id) {
|
|
1031
|
+
var response, record;
|
|
1032
|
+
return _regeneratorRuntime().wrap(function _callee19$(_context19) {
|
|
1033
|
+
while (1) switch (_context19.prev = _context19.next) {
|
|
1034
|
+
case 0:
|
|
1035
|
+
_context19.prev = 0;
|
|
1036
|
+
_context19.next = 3;
|
|
1037
|
+
return this.load('<@filekit.file>', id);
|
|
1038
|
+
case 3:
|
|
1039
|
+
response = _context19.sent;
|
|
1040
|
+
if (response) {
|
|
1041
|
+
_context19.next = 6;
|
|
1042
|
+
break;
|
|
1043
|
+
}
|
|
1044
|
+
return _context19.abrupt("return", null);
|
|
1045
|
+
case 6:
|
|
1046
|
+
record = response.toRecord();
|
|
1047
|
+
return _context19.abrupt("return", new _rbt_file["default"](record, this.axios, this.localDb));
|
|
1048
|
+
case 10:
|
|
1049
|
+
_context19.prev = 10;
|
|
1050
|
+
_context19.t0 = _context19["catch"](0);
|
|
1051
|
+
return _context19.abrupt("return", this._handleError(_context19.t0));
|
|
1052
|
+
case 13:
|
|
1053
|
+
case "end":
|
|
1054
|
+
return _context19.stop();
|
|
1055
|
+
}
|
|
1056
|
+
}, _callee19, this, [[0, 10]]);
|
|
1057
|
+
}));
|
|
1058
|
+
function loadFile(_x10) {
|
|
1059
|
+
return _loadFile.apply(this, arguments);
|
|
621
1060
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
1061
|
+
return loadFile;
|
|
1062
|
+
}()
|
|
1063
|
+
}, {
|
|
1064
|
+
key: "loadFiles",
|
|
1065
|
+
value: function () {
|
|
1066
|
+
var _loadFiles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(ids) {
|
|
1067
|
+
var _this5 = this;
|
|
1068
|
+
var responses;
|
|
1069
|
+
return _regeneratorRuntime().wrap(function _callee20$(_context20) {
|
|
1070
|
+
while (1) switch (_context20.prev = _context20.next) {
|
|
1071
|
+
case 0:
|
|
1072
|
+
_context20.prev = 0;
|
|
1073
|
+
_context20.next = 3;
|
|
1074
|
+
return this.load('<@filekit.file>', ids);
|
|
1075
|
+
case 3:
|
|
1076
|
+
responses = _context20.sent;
|
|
1077
|
+
if (!(!responses || !Array.isArray(responses))) {
|
|
1078
|
+
_context20.next = 6;
|
|
1079
|
+
break;
|
|
1080
|
+
}
|
|
1081
|
+
return _context20.abrupt("return", []);
|
|
1082
|
+
case 6:
|
|
1083
|
+
return _context20.abrupt("return", responses.map(function (response) {
|
|
1084
|
+
var record = response.toRecord();
|
|
1085
|
+
return new _rbt_file["default"](record, _this5.axios, _this5.localDb);
|
|
1086
|
+
}));
|
|
1087
|
+
case 9:
|
|
1088
|
+
_context20.prev = 9;
|
|
1089
|
+
_context20.t0 = _context20["catch"](0);
|
|
1090
|
+
this._handleError(_context20.t0); // Handle errors (log or process as needed)
|
|
1091
|
+
return _context20.abrupt("return", []);
|
|
1092
|
+
case 13:
|
|
1093
|
+
case "end":
|
|
1094
|
+
return _context20.stop();
|
|
1095
|
+
}
|
|
1096
|
+
}, _callee20, this, [[0, 9]]);
|
|
1097
|
+
}));
|
|
1098
|
+
function loadFiles(_x11) {
|
|
1099
|
+
return _loadFiles.apply(this, arguments);
|
|
1100
|
+
}
|
|
1101
|
+
return loadFiles;
|
|
1102
|
+
}()
|
|
1103
|
+
/**
|
|
1104
|
+
* Creates a new object of the given type.
|
|
1105
|
+
*
|
|
1106
|
+
* @param {string} type - The type of object to create.
|
|
1107
|
+
* @param {Object} dataHash - The data for the new object.
|
|
1108
|
+
* @param {Object} options - Additional options including enableRealtime.
|
|
1109
|
+
* @returns {Promise<RbtObject>} - The newly created object as an RbtObject.
|
|
1110
|
+
*/
|
|
1111
|
+
}, {
|
|
1112
|
+
key: "create",
|
|
1113
|
+
value: (function () {
|
|
1114
|
+
var _create = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(type) {
|
|
1115
|
+
var dataHash,
|
|
1116
|
+
options,
|
|
1117
|
+
response,
|
|
1118
|
+
record,
|
|
1119
|
+
_args21 = arguments;
|
|
1120
|
+
return _regeneratorRuntime().wrap(function _callee21$(_context21) {
|
|
1121
|
+
while (1) switch (_context21.prev = _context21.next) {
|
|
1122
|
+
case 0:
|
|
1123
|
+
dataHash = _args21.length > 1 && _args21[1] !== undefined ? _args21[1] : {};
|
|
1124
|
+
options = _args21.length > 2 && _args21[2] !== undefined ? _args21[2] : {};
|
|
1125
|
+
_context21.prev = 2;
|
|
1126
|
+
_context21.next = 5;
|
|
1127
|
+
return this.axios.post('/object_service/createObject', [type, dataHash]);
|
|
1128
|
+
case 5:
|
|
1129
|
+
response = _context21.sent;
|
|
1130
|
+
record = response.data;
|
|
1131
|
+
if (dataHash) {
|
|
1132
|
+
record.data = dataHash;
|
|
1133
|
+
}
|
|
1134
|
+
return _context21.abrupt("return", new _rbt_object["default"](record, this.axios, {
|
|
1135
|
+
isNew: true,
|
|
1136
|
+
websocketClient: this.websocketClient,
|
|
1137
|
+
enableRealtime: options.enableRealtime || false
|
|
1138
|
+
}));
|
|
1139
|
+
case 11:
|
|
1140
|
+
_context21.prev = 11;
|
|
1141
|
+
_context21.t0 = _context21["catch"](2);
|
|
1142
|
+
return _context21.abrupt("return", this._handleError(_context21.t0));
|
|
1143
|
+
case 14:
|
|
1144
|
+
case "end":
|
|
1145
|
+
return _context21.stop();
|
|
1146
|
+
}
|
|
1147
|
+
}, _callee21, this, [[2, 11]]);
|
|
1148
|
+
}));
|
|
1149
|
+
function create(_x12) {
|
|
1150
|
+
return _create.apply(this, arguments);
|
|
1151
|
+
}
|
|
1152
|
+
return create;
|
|
1153
|
+
}()
|
|
1154
|
+
/**
|
|
1155
|
+
* Queries objects of a given type based on specified parameters.
|
|
1156
|
+
*
|
|
1157
|
+
* @param {string} type - The type of object to query, specified as a doctree.typedef.
|
|
1158
|
+
* @param {Object} params - The query parameters, including optional filters and configurations.
|
|
1159
|
+
* @returns {Promise<Array<RbtObject>>} - An array of queried objects as RbtObjects.
|
|
1160
|
+
*
|
|
1161
|
+
* The `params` object can include the following properties:
|
|
1162
|
+
* - where: A SQL-like where clause string for filtering the results.
|
|
1163
|
+
* - orderBy: An object specifying the ordering of the results. It should include:
|
|
1164
|
+
* - column: The attribute name to sort by. This must be either a column in the @doctree.model schema or an indexed type attribute.
|
|
1165
|
+
* - direction: The sort direction, either 'ASC' for ascending or 'DESC' for descending.
|
|
1166
|
+
* - limit: An object to control the pagination of results. It includes:
|
|
1167
|
+
* - offset: The starting point from where to fetch the results.
|
|
1168
|
+
* - results: The maximum number of results to return.
|
|
1169
|
+
* - requestAttrs: An array of attribute paths to include in the response (e.g., ['id', 'configs.title', 'configs.description']).
|
|
1170
|
+
* If not provided, all attributes are returned.
|
|
1171
|
+
* - excludeAttrs: An array of attribute paths to exclude from the response (e.g., ['details.log', 'internalData']).
|
|
1172
|
+
* Excludes the specified paths and all their subpaths.
|
|
1173
|
+
* - resolveReferences: An array of attribute names whose references should be resolved in the returned objects.
|
|
1174
|
+
* - timeout: A numerical value in milliseconds to set a maximum time limit for the query execution.
|
|
1175
|
+
*
|
|
1176
|
+
* Example usage:
|
|
1177
|
+
* query("<@testuser>", {
|
|
1178
|
+
* where: 'email="tom@pospa.com"',
|
|
1179
|
+
* orderBy: { column: 'timeCreated', direction: 'DESC' },
|
|
1180
|
+
* limit: { offset: 0, results: 50 },
|
|
1181
|
+
* requestAttrs: ['id', 'configs.title'],
|
|
1182
|
+
* excludeAttrs: ['details.log'],
|
|
1183
|
+
* resolveReferences: ['translatableContent']
|
|
1184
|
+
* });
|
|
1185
|
+
*
|
|
1186
|
+
* Note: A default orderBy is applied if none is provided, ordering items by 'timeCreated' in descending order.
|
|
1187
|
+
*/
|
|
1188
|
+
)
|
|
1189
|
+
}, {
|
|
1190
|
+
key: "query",
|
|
1191
|
+
value: (function () {
|
|
1192
|
+
var _query = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(type) {
|
|
1193
|
+
var _this6 = this;
|
|
1194
|
+
var params,
|
|
1195
|
+
paramsKey,
|
|
1196
|
+
validParams,
|
|
1197
|
+
invalidParams,
|
|
1198
|
+
defaultOrderBy,
|
|
1199
|
+
defaultLimit,
|
|
1200
|
+
mergedParams,
|
|
1201
|
+
currentTime,
|
|
1202
|
+
cacheEntry,
|
|
1203
|
+
responsePromise,
|
|
1204
|
+
processingPromise,
|
|
1205
|
+
_args22 = arguments;
|
|
1206
|
+
return _regeneratorRuntime().wrap(function _callee22$(_context22) {
|
|
1207
|
+
while (1) switch (_context22.prev = _context22.next) {
|
|
1208
|
+
case 0:
|
|
1209
|
+
params = _args22.length > 1 && _args22[1] !== undefined ? _args22[1] : {};
|
|
1210
|
+
_context22.prev = 1;
|
|
1211
|
+
//console.log('RBTAPI.query INIT', type, params);
|
|
1212
|
+
// Validate parameters - reject invalid parameter names
|
|
1213
|
+
validParams = ['type', 'where', 'orderBy', 'limit', 'resolveReferences', 'requestAttrs', 'excludeAttrs', 'timeout', 'enableRealtime'];
|
|
1214
|
+
invalidParams = Object.keys(params).filter(function (key) {
|
|
1215
|
+
return !validParams.includes(key);
|
|
1216
|
+
});
|
|
1217
|
+
if (!(invalidParams.length > 0)) {
|
|
1218
|
+
_context22.next = 6;
|
|
1219
|
+
break;
|
|
1220
|
+
}
|
|
1221
|
+
throw new Error("Invalid query parameter(s): ".concat(invalidParams.join(', '), ". Valid parameters are: ").concat(validParams.join(', ')));
|
|
1222
|
+
case 6:
|
|
1223
|
+
// Warn if enableRealtime is passed to query() - it should only be used by load()
|
|
1224
|
+
if (params.enableRealtime) {}
|
|
1225
|
+
params.type = type;
|
|
1226
|
+
|
|
1227
|
+
// Default ordering and pagination
|
|
1228
|
+
defaultOrderBy = {
|
|
1229
|
+
orderBy: {
|
|
1230
|
+
column: 'timeCreated',
|
|
1231
|
+
direction: 'DESC'
|
|
1232
|
+
}
|
|
1233
|
+
};
|
|
1234
|
+
defaultLimit = {
|
|
1235
|
+
limit: {
|
|
1236
|
+
offset: 0,
|
|
1237
|
+
results: 50
|
|
1238
|
+
}
|
|
1239
|
+
}; // Merge defaults with provided params
|
|
1240
|
+
mergedParams = _objectSpread(_objectSpread(_objectSpread({}, defaultOrderBy), defaultLimit), params); // Check cache for an existing request
|
|
1241
|
+
currentTime = Date.now();
|
|
1242
|
+
paramsKey = JSON.stringify(mergedParams);
|
|
1243
|
+
cacheEntry = this.requestCache[paramsKey];
|
|
1244
|
+
if (!(cacheEntry && currentTime - cacheEntry.time < 10000)) {
|
|
1245
|
+
_context22.next = 16;
|
|
1246
|
+
break;
|
|
1247
|
+
}
|
|
1248
|
+
return _context22.abrupt("return", cacheEntry.val);
|
|
1249
|
+
case 16:
|
|
1250
|
+
// Create the response promise
|
|
1251
|
+
responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]); // Cache the promise of processing data, not just the raw response
|
|
1252
|
+
processingPromise = responsePromise.then(function (response) {
|
|
1253
|
+
return _this6._processResponseData(response, params);
|
|
1254
|
+
})["catch"](function (e) {
|
|
1255
|
+
delete _this6.requestCache[paramsKey]; // Ensure cache cleanup on failure
|
|
1256
|
+
//console.log('RBTAPI.query ERROR (Processing)', paramsKey, e);
|
|
1257
|
+
return _this6._handleError(e);
|
|
1258
|
+
}); // Store the promise of the processed data in the cache
|
|
1259
|
+
this.requestCache[paramsKey] = {
|
|
1260
|
+
val: processingPromise,
|
|
1261
|
+
time: currentTime
|
|
1262
|
+
};
|
|
1263
|
+
|
|
1264
|
+
// Await the processing promise for this call to get processed data
|
|
1265
|
+
_context22.next = 21;
|
|
1266
|
+
return processingPromise;
|
|
1267
|
+
case 21:
|
|
1268
|
+
return _context22.abrupt("return", _context22.sent);
|
|
1269
|
+
case 24:
|
|
1270
|
+
_context22.prev = 24;
|
|
1271
|
+
_context22.t0 = _context22["catch"](1);
|
|
1272
|
+
delete this.requestCache[paramsKey]; // Ensure cache cleanup on error
|
|
1273
|
+
//console.log('RBTAPI.query ERROR', paramsKey, e);
|
|
1274
|
+
return _context22.abrupt("return", this._handleError(_context22.t0));
|
|
1275
|
+
case 28:
|
|
1276
|
+
case "end":
|
|
1277
|
+
return _context22.stop();
|
|
1278
|
+
}
|
|
1279
|
+
}, _callee22, this, [[1, 24]]);
|
|
1280
|
+
}));
|
|
1281
|
+
function query(_x13) {
|
|
1282
|
+
return _query.apply(this, arguments);
|
|
1283
|
+
}
|
|
1284
|
+
return query;
|
|
1285
|
+
}())
|
|
1286
|
+
}, {
|
|
1287
|
+
key: "_processResponseData",
|
|
1288
|
+
value: function _processResponseData(response) {
|
|
1289
|
+
var _this7 = this;
|
|
1290
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1291
|
+
if (response.data.ok === false) {
|
|
1292
|
+
return this._handleError(response);
|
|
626
1293
|
}
|
|
627
|
-
|
|
1294
|
+
if (Array.isArray(response.data.items)) {
|
|
1295
|
+
//console.log('RBTAPI.query RESPONSE PRE', response.data.items);
|
|
628
1296
|
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
direction: 'DESC'
|
|
634
|
-
}
|
|
635
|
-
};
|
|
636
|
-
const defaultLimit = {
|
|
637
|
-
limit: {
|
|
638
|
-
offset: 0,
|
|
639
|
-
results: 50
|
|
1297
|
+
// Ensure WebSocket client is available if realtime is requested
|
|
1298
|
+
var websocketClient = this.websocketClient;
|
|
1299
|
+
if (options.enableRealtime && !websocketClient) {
|
|
1300
|
+
websocketClient = this.getWebSocketClient();
|
|
640
1301
|
}
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
...params
|
|
648
|
-
};
|
|
649
|
-
|
|
650
|
-
// Check cache for an existing request
|
|
651
|
-
const currentTime = Date.now();
|
|
652
|
-
paramsKey = JSON.stringify(mergedParams);
|
|
653
|
-
const cacheEntry = this.requestCache[paramsKey];
|
|
654
|
-
if (cacheEntry && currentTime - cacheEntry.time < 10000) {
|
|
655
|
-
// 10000 ms = 10 seconds
|
|
656
|
-
//console.log('RBTAPI.query CACHED', type, paramsKey);
|
|
657
|
-
return cacheEntry.val;
|
|
1302
|
+
response.data.items = response.data.items.map(function (record) {
|
|
1303
|
+
return new _rbt_object["default"](record, _this7.axios, {
|
|
1304
|
+
websocketClient: websocketClient,
|
|
1305
|
+
enableRealtime: options.enableRealtime || false
|
|
1306
|
+
});
|
|
1307
|
+
});
|
|
658
1308
|
}
|
|
659
1309
|
|
|
660
|
-
//
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
// Cache the promise of processing data, not just the raw response
|
|
664
|
-
const processingPromise = responsePromise.then(response => this._processResponseData(response, params)).catch(e => {
|
|
665
|
-
delete this.requestCache[paramsKey]; // Ensure cache cleanup on failure
|
|
666
|
-
//console.log('RBTAPI.query ERROR (Processing)', paramsKey, e);
|
|
667
|
-
return this._handleError(e);
|
|
668
|
-
});
|
|
669
|
-
|
|
670
|
-
// Store the promise of the processed data in the cache
|
|
671
|
-
this.requestCache[paramsKey] = {
|
|
672
|
-
val: processingPromise,
|
|
673
|
-
time: currentTime
|
|
674
|
-
};
|
|
675
|
-
|
|
676
|
-
// Await the processing promise for this call to get processed data
|
|
677
|
-
return await processingPromise;
|
|
678
|
-
} catch (e) {
|
|
679
|
-
delete this.requestCache[paramsKey]; // Ensure cache cleanup on error
|
|
680
|
-
//console.log('RBTAPI.query ERROR', paramsKey, e);
|
|
681
|
-
return this._handleError(e);
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
_processResponseData(response, options = {}) {
|
|
685
|
-
if (response.data.ok === false) {
|
|
686
|
-
return this._handleError(response);
|
|
1310
|
+
//console.log('RBTAPI.query RESPONSE POST', response.data.items);
|
|
1311
|
+
return response.data.items;
|
|
687
1312
|
}
|
|
688
|
-
if (Array.isArray(response.data.items)) {
|
|
689
|
-
//console.log('RBTAPI.query RESPONSE PRE', response.data.items);
|
|
690
1313
|
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
1314
|
+
/**
|
|
1315
|
+
* Loads one or multiple objects of a given type by their IDs.
|
|
1316
|
+
*
|
|
1317
|
+
* @param {string} type - The type of object to load.
|
|
1318
|
+
* @param {Array<string>|string} ids - The ID(s) of the object(s) to load.
|
|
1319
|
+
*
|
|
1320
|
+
* @returns {Promise<RbtObject|RbtObject[]>} - The loaded object(s) as RbtObject(s).
|
|
1321
|
+
*/
|
|
1322
|
+
}, {
|
|
1323
|
+
key: "load",
|
|
1324
|
+
value: (function () {
|
|
1325
|
+
var _load = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(type, ids) {
|
|
1326
|
+
var _this8 = this;
|
|
1327
|
+
var params,
|
|
1328
|
+
mergedParams,
|
|
1329
|
+
cachedObjects,
|
|
1330
|
+
missingIds,
|
|
1331
|
+
_iterator3,
|
|
1332
|
+
_step3,
|
|
1333
|
+
id,
|
|
1334
|
+
_cacheKey,
|
|
1335
|
+
cached,
|
|
1336
|
+
hitLogKey,
|
|
1337
|
+
loadedObjects,
|
|
1338
|
+
bulkMissLogKey,
|
|
1339
|
+
enableRealtime,
|
|
1340
|
+
queryParams,
|
|
1341
|
+
_iterator4,
|
|
1342
|
+
_step4,
|
|
1343
|
+
obj,
|
|
1344
|
+
cacheKey,
|
|
1345
|
+
setLogKey,
|
|
1346
|
+
result,
|
|
1347
|
+
_iterator5,
|
|
1348
|
+
_step5,
|
|
1349
|
+
_id,
|
|
1350
|
+
_cacheKey2,
|
|
1351
|
+
_obj,
|
|
1352
|
+
_cacheKey3,
|
|
1353
|
+
_cached,
|
|
1354
|
+
_hitLogKey,
|
|
1355
|
+
pendingKey,
|
|
1356
|
+
missLogKey,
|
|
1357
|
+
loadPromise,
|
|
1358
|
+
_args24 = arguments;
|
|
1359
|
+
return _regeneratorRuntime().wrap(function _callee24$(_context24) {
|
|
1360
|
+
while (1) switch (_context24.prev = _context24.next) {
|
|
1361
|
+
case 0:
|
|
1362
|
+
params = _args24.length > 2 && _args24[2] !== undefined ? _args24[2] : {};
|
|
1363
|
+
if (type == '<@iac.user>') {
|
|
1364
|
+
debugger;
|
|
1365
|
+
}
|
|
1366
|
+
_context24.prev = 2;
|
|
1367
|
+
if (!Array.isArray(ids)) {
|
|
1368
|
+
_context24.next = 25;
|
|
1369
|
+
break;
|
|
1370
|
+
}
|
|
1371
|
+
// For array requests, check cache for each ID and only load missing ones
|
|
1372
|
+
cachedObjects = [];
|
|
1373
|
+
missingIds = [];
|
|
1374
|
+
_iterator3 = _createForOfIteratorHelper(ids);
|
|
1375
|
+
try {
|
|
1376
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
1377
|
+
id = _step3.value;
|
|
1378
|
+
_cacheKey = "".concat(type, ":").concat(id);
|
|
1379
|
+
cached = this._objectCache.get(_cacheKey);
|
|
1380
|
+
if (cached) {
|
|
1381
|
+
// Only log cache hits once per object to reduce spam
|
|
1382
|
+
hitLogKey = "hit:".concat(_cacheKey);
|
|
1383
|
+
if (!this._loggedCacheEvents.has(hitLogKey)) {
|
|
1384
|
+
this._loggedCacheEvents.add(hitLogKey);
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
// If realtime is requested but cached object doesn't have it, upgrade it
|
|
1388
|
+
if (params.enableRealtime && !cached._realtime) {
|
|
1389
|
+
cached._initRealtime();
|
|
1390
|
+
}
|
|
1391
|
+
cachedObjects.push(cached);
|
|
1392
|
+
} else {
|
|
1393
|
+
missingIds.push(id);
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
// Load missing objects
|
|
1398
|
+
} catch (err) {
|
|
1399
|
+
_iterator3.e(err);
|
|
1400
|
+
} finally {
|
|
1401
|
+
_iterator3.f();
|
|
1402
|
+
}
|
|
1403
|
+
loadedObjects = [];
|
|
1404
|
+
if (!(missingIds.length > 0)) {
|
|
1405
|
+
_context24.next = 19;
|
|
1406
|
+
break;
|
|
1407
|
+
}
|
|
1408
|
+
// Only log bulk cache miss once
|
|
1409
|
+
bulkMissLogKey = "bulk-miss:".concat(type, ":").concat(missingIds.join(','));
|
|
1410
|
+
if (!this._loggedCacheEvents.has(bulkMissLogKey)) {
|
|
1411
|
+
this._loggedCacheEvents.add(bulkMissLogKey);
|
|
1412
|
+
}
|
|
713
1413
|
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
* @param {Array<string>|string} ids - The ID(s) of the object(s) to load.
|
|
719
|
-
*
|
|
720
|
-
* @returns {Promise<RbtObject|RbtObject[]>} - The loaded object(s) as RbtObject(s).
|
|
721
|
-
*/
|
|
722
|
-
async load(type, ids, params = {}) {
|
|
723
|
-
if (type == '<@iac.user>') {
|
|
724
|
-
debugger;
|
|
725
|
-
}
|
|
726
|
-
try {
|
|
727
|
-
let mergedParams;
|
|
728
|
-
if (Array.isArray(ids)) {
|
|
729
|
-
// For array requests, check cache for each ID and only load missing ones
|
|
730
|
-
const cachedObjects = [];
|
|
731
|
-
const missingIds = [];
|
|
732
|
-
for (const id of ids) {
|
|
733
|
-
const cacheKey = `${type}:${id}`;
|
|
734
|
-
const cached = this._objectCache.get(cacheKey);
|
|
735
|
-
if (cached) {
|
|
736
|
-
// Only log cache hits once per object to reduce spam
|
|
737
|
-
const hitLogKey = `hit:${cacheKey}`;
|
|
738
|
-
if (!this._loggedCacheEvents.has(hitLogKey)) {
|
|
739
|
-
console.log('[AgentProviderSync] 🎯 roboto.load cache HIT:', {
|
|
740
|
-
type,
|
|
741
|
-
id,
|
|
742
|
-
hasRealtime: !!cached._realtime,
|
|
743
|
-
requestedRealtime: !!params.enableRealtime
|
|
1414
|
+
// Remove load-specific params that shouldn't be passed to query
|
|
1415
|
+
enableRealtime = params.enableRealtime, queryParams = _objectWithoutProperties(params, _excluded);
|
|
1416
|
+
mergedParams = _objectSpread(_objectSpread({}, queryParams), {}, {
|
|
1417
|
+
where: "id IN (\"".concat(missingIds.join("\",\""), "\")")
|
|
744
1418
|
});
|
|
745
|
-
|
|
746
|
-
|
|
1419
|
+
_context24.next = 16;
|
|
1420
|
+
return this.query(type, mergedParams);
|
|
1421
|
+
case 16:
|
|
1422
|
+
loadedObjects = _context24.sent;
|
|
1423
|
+
// Cache the newly loaded objects
|
|
1424
|
+
_iterator4 = _createForOfIteratorHelper(loadedObjects);
|
|
1425
|
+
try {
|
|
1426
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
1427
|
+
obj = _step4.value;
|
|
1428
|
+
cacheKey = "".concat(type, ":").concat(obj.id);
|
|
1429
|
+
this._objectCache.set(cacheKey, obj);
|
|
1430
|
+
|
|
1431
|
+
// Only log cache set once per object to reduce spam
|
|
1432
|
+
setLogKey = "set:".concat(cacheKey);
|
|
1433
|
+
if (!this._loggedCacheEvents.has(setLogKey)) {
|
|
1434
|
+
this._loggedCacheEvents.add(setLogKey);
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
} catch (err) {
|
|
1438
|
+
_iterator4.e(err);
|
|
1439
|
+
} finally {
|
|
1440
|
+
_iterator4.f();
|
|
1441
|
+
}
|
|
1442
|
+
case 19:
|
|
1443
|
+
// Return combined results in original order
|
|
1444
|
+
result = [];
|
|
1445
|
+
_iterator5 = _createForOfIteratorHelper(ids);
|
|
1446
|
+
try {
|
|
1447
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
1448
|
+
_id = _step5.value;
|
|
1449
|
+
_cacheKey2 = "".concat(type, ":").concat(_id);
|
|
1450
|
+
_obj = this._objectCache.get(_cacheKey2);
|
|
1451
|
+
if (_obj) {
|
|
1452
|
+
// Ensure realtime is enabled if requested
|
|
1453
|
+
if (params.enableRealtime && !_obj._realtime) {
|
|
1454
|
+
_obj._initRealtime();
|
|
1455
|
+
}
|
|
1456
|
+
result.push(_obj);
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
} catch (err) {
|
|
1460
|
+
_iterator5.e(err);
|
|
1461
|
+
} finally {
|
|
1462
|
+
_iterator5.f();
|
|
1463
|
+
}
|
|
1464
|
+
return _context24.abrupt("return", result);
|
|
1465
|
+
case 25:
|
|
1466
|
+
// For single object requests, check cache first
|
|
1467
|
+
_cacheKey3 = "".concat(type, ":").concat(ids);
|
|
1468
|
+
_cached = this._objectCache.get(_cacheKey3);
|
|
1469
|
+
if (!_cached) {
|
|
1470
|
+
_context24.next = 32;
|
|
1471
|
+
break;
|
|
1472
|
+
}
|
|
1473
|
+
// Only log cache hits once per object to reduce spam
|
|
1474
|
+
_hitLogKey = "hit:".concat(_cacheKey3);
|
|
1475
|
+
if (!this._loggedCacheEvents.has(_hitLogKey) || void 0) {
|
|
1476
|
+
this._loggedCacheEvents.add(_hitLogKey);
|
|
1477
|
+
}
|
|
747
1478
|
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
1479
|
+
// If realtime is requested but cached object doesn't have it, upgrade it
|
|
1480
|
+
if (params.enableRealtime && !_cached._realtime) {
|
|
1481
|
+
_cached._initRealtime();
|
|
1482
|
+
}
|
|
1483
|
+
return _context24.abrupt("return", _cached);
|
|
1484
|
+
case 32:
|
|
1485
|
+
// Check if we're already loading this object
|
|
1486
|
+
pendingKey = "".concat(type, ":").concat(ids);
|
|
1487
|
+
if (!this._pendingLoads.has(pendingKey)) {
|
|
1488
|
+
_context24.next = 37;
|
|
1489
|
+
break;
|
|
1490
|
+
}
|
|
1491
|
+
_context24.next = 36;
|
|
1492
|
+
return this._pendingLoads.get(pendingKey);
|
|
1493
|
+
case 36:
|
|
1494
|
+
return _context24.abrupt("return", _context24.sent);
|
|
1495
|
+
case 37:
|
|
1496
|
+
// Only log cache miss once per object to reduce spam
|
|
1497
|
+
missLogKey = "miss:".concat(_cacheKey3);
|
|
1498
|
+
if (!this._loggedCacheEvents.has(missLogKey)) {
|
|
1499
|
+
this._loggedCacheEvents.add(missLogKey);
|
|
1500
|
+
}
|
|
761
1501
|
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
1502
|
+
// Create the loading promise and store it to prevent duplicate requests
|
|
1503
|
+
loadPromise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
|
|
1504
|
+
var _enableRealtime, _queryParams, res, _obj2, _setLogKey;
|
|
1505
|
+
return _regeneratorRuntime().wrap(function _callee23$(_context23) {
|
|
1506
|
+
while (1) switch (_context23.prev = _context23.next) {
|
|
1507
|
+
case 0:
|
|
1508
|
+
_context23.prev = 0;
|
|
1509
|
+
// Remove load-specific params that shouldn't be passed to query
|
|
1510
|
+
_enableRealtime = params.enableRealtime, _queryParams = _objectWithoutProperties(params, _excluded2);
|
|
1511
|
+
mergedParams = _objectSpread(_objectSpread({}, _queryParams), {}, {
|
|
1512
|
+
where: "id=\"".concat(ids, "\"")
|
|
1513
|
+
});
|
|
1514
|
+
_context23.next = 5;
|
|
1515
|
+
return _this8.query(type, mergedParams);
|
|
1516
|
+
case 5:
|
|
1517
|
+
res = _context23.sent;
|
|
1518
|
+
_obj2 = res[0];
|
|
1519
|
+
if (_obj2) {
|
|
1520
|
+
// Cache the loaded object
|
|
1521
|
+
_this8._objectCache.set(_cacheKey3, _obj2);
|
|
1522
|
+
|
|
1523
|
+
// Only log cache set once per object to reduce spam
|
|
1524
|
+
_setLogKey = "set:".concat(_cacheKey3);
|
|
1525
|
+
if (!_this8._loggedCacheEvents.has(_setLogKey)) {
|
|
1526
|
+
_this8._loggedCacheEvents.add(_setLogKey);
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
return _context23.abrupt("return", _obj2);
|
|
1530
|
+
case 9:
|
|
1531
|
+
_context23.prev = 9;
|
|
1532
|
+
// Remove from pending loads
|
|
1533
|
+
_this8._pendingLoads["delete"](pendingKey);
|
|
1534
|
+
return _context23.finish(9);
|
|
1535
|
+
case 12:
|
|
1536
|
+
case "end":
|
|
1537
|
+
return _context23.stop();
|
|
1538
|
+
}
|
|
1539
|
+
}, _callee23, null, [[0,, 9, 12]]);
|
|
1540
|
+
}))(); // Store the promise so other concurrent requests can await it
|
|
1541
|
+
this._pendingLoads.set(pendingKey, loadPromise);
|
|
1542
|
+
_context24.next = 43;
|
|
1543
|
+
return loadPromise;
|
|
1544
|
+
case 43:
|
|
1545
|
+
return _context24.abrupt("return", _context24.sent);
|
|
1546
|
+
case 44:
|
|
1547
|
+
_context24.next = 49;
|
|
1548
|
+
break;
|
|
1549
|
+
case 46:
|
|
1550
|
+
_context24.prev = 46;
|
|
1551
|
+
_context24.t0 = _context24["catch"](2);
|
|
1552
|
+
return _context24.abrupt("return", this._handleError(_context24.t0));
|
|
1553
|
+
case 49:
|
|
1554
|
+
case "end":
|
|
1555
|
+
return _context24.stop();
|
|
773
1556
|
}
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
1557
|
+
}, _callee24, this, [[2, 46]]);
|
|
1558
|
+
}));
|
|
1559
|
+
function load(_x14, _x15) {
|
|
1560
|
+
return _load.apply(this, arguments);
|
|
1561
|
+
}
|
|
1562
|
+
return load;
|
|
1563
|
+
}()
|
|
1564
|
+
/**
|
|
1565
|
+
* Clears the object cache. Useful for cache invalidation.
|
|
1566
|
+
* @param {string} type - Optional object type to clear. If not provided, clears all.
|
|
1567
|
+
* @param {string} id - Optional object ID to clear. If not provided with type, clears all objects of that type.
|
|
1568
|
+
*/
|
|
1569
|
+
)
|
|
1570
|
+
}, {
|
|
1571
|
+
key: "clearCache",
|
|
1572
|
+
value: function clearCache() {
|
|
1573
|
+
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
1574
|
+
var id = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
1575
|
+
if (type && id) {
|
|
1576
|
+
// Clear specific object
|
|
1577
|
+
var cacheKey = "".concat(type, ":").concat(id);
|
|
1578
|
+
var removed = this._objectCache["delete"](cacheKey);
|
|
1579
|
+
|
|
1580
|
+
// Clear related log tracking
|
|
1581
|
+
this._loggedCacheEvents["delete"]("hit:".concat(cacheKey));
|
|
1582
|
+
this._loggedCacheEvents["delete"]("miss:".concat(cacheKey));
|
|
1583
|
+
this._loggedCacheEvents["delete"]("set:".concat(cacheKey));
|
|
1584
|
+
} else if (type) {
|
|
1585
|
+
// Clear all objects of a specific type
|
|
1586
|
+
var removedCount = 0;
|
|
1587
|
+
var _iterator6 = _createForOfIteratorHelper(this._objectCache),
|
|
1588
|
+
_step6;
|
|
1589
|
+
try {
|
|
1590
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
1591
|
+
var _step6$value = _slicedToArray(_step6.value, 1),
|
|
1592
|
+
key = _step6$value[0];
|
|
1593
|
+
if (key.startsWith("".concat(type, ":"))) {
|
|
1594
|
+
this._objectCache["delete"](key);
|
|
1595
|
+
removedCount++;
|
|
799
1596
|
}
|
|
800
1597
|
}
|
|
801
|
-
}
|
|
802
1598
|
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
1599
|
+
// Clear related log tracking for this type
|
|
1600
|
+
} catch (err) {
|
|
1601
|
+
_iterator6.e(err);
|
|
1602
|
+
} finally {
|
|
1603
|
+
_iterator6.f();
|
|
1604
|
+
}
|
|
1605
|
+
var _iterator7 = _createForOfIteratorHelper(this._loggedCacheEvents),
|
|
1606
|
+
_step7;
|
|
1607
|
+
try {
|
|
1608
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
1609
|
+
var logKey = _step7.value;
|
|
1610
|
+
if (logKey.includes("".concat(type, ":"))) {
|
|
1611
|
+
this._loggedCacheEvents["delete"](logKey);
|
|
812
1612
|
}
|
|
813
|
-
result.push(obj);
|
|
814
1613
|
}
|
|
1614
|
+
} catch (err) {
|
|
1615
|
+
_iterator7.e(err);
|
|
1616
|
+
} finally {
|
|
1617
|
+
_iterator7.f();
|
|
815
1618
|
}
|
|
816
|
-
return result;
|
|
817
1619
|
} else {
|
|
818
|
-
//
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
const hitLogKey = `hit:${cacheKey}`;
|
|
824
|
-
if (!this._loggedCacheEvents.has(hitLogKey) || console.log('[AgentProviderSync] 🎯 roboto.load cache HIT:', {
|
|
825
|
-
type,
|
|
826
|
-
id: ids,
|
|
827
|
-
hasRealtime: !!cached._realtime,
|
|
828
|
-
requestedRealtime: !!params.enableRealtime
|
|
829
|
-
})) {
|
|
830
|
-
this._loggedCacheEvents.add(hitLogKey);
|
|
831
|
-
}
|
|
832
|
-
|
|
833
|
-
// If realtime is requested but cached object doesn't have it, upgrade it
|
|
834
|
-
if (params.enableRealtime && !cached._realtime) {
|
|
835
|
-
console.log('[AgentProviderSync] 🔄 Upgrading cached object to realtime:', {
|
|
836
|
-
type,
|
|
837
|
-
id: ids
|
|
838
|
-
});
|
|
839
|
-
cached._initRealtime();
|
|
840
|
-
}
|
|
841
|
-
return cached;
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
// Check if we're already loading this object
|
|
845
|
-
const pendingKey = `${type}:${ids}`;
|
|
846
|
-
if (this._pendingLoads.has(pendingKey)) {
|
|
847
|
-
// Wait for the existing request to complete
|
|
848
|
-
return await this._pendingLoads.get(pendingKey);
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
// Only log cache miss once per object to reduce spam
|
|
852
|
-
const missLogKey = `miss:${cacheKey}`;
|
|
853
|
-
if (!this._loggedCacheEvents.has(missLogKey)) {
|
|
854
|
-
console.log('[AgentProviderSync] 📦 roboto.load cache MISS, loading:', {
|
|
855
|
-
type,
|
|
856
|
-
id: ids
|
|
857
|
-
});
|
|
858
|
-
this._loggedCacheEvents.add(missLogKey);
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
// Create the loading promise and store it to prevent duplicate requests
|
|
862
|
-
const loadPromise = (async () => {
|
|
863
|
-
try {
|
|
864
|
-
// Remove load-specific params that shouldn't be passed to query
|
|
865
|
-
const {
|
|
866
|
-
enableRealtime,
|
|
867
|
-
...queryParams
|
|
868
|
-
} = params;
|
|
869
|
-
mergedParams = {
|
|
870
|
-
...queryParams,
|
|
871
|
-
where: `id="${ids}"`
|
|
872
|
-
};
|
|
873
|
-
let res = await this.query(type, mergedParams);
|
|
874
|
-
const obj = res[0];
|
|
875
|
-
if (obj) {
|
|
876
|
-
// Cache the loaded object
|
|
877
|
-
this._objectCache.set(cacheKey, obj);
|
|
878
|
-
|
|
879
|
-
// Only log cache set once per object to reduce spam
|
|
880
|
-
const setLogKey = `set:${cacheKey}`;
|
|
881
|
-
if (!this._loggedCacheEvents.has(setLogKey)) {
|
|
882
|
-
console.log('[AgentProviderSync] 💾 roboto.load cached object:', {
|
|
883
|
-
type,
|
|
884
|
-
id: ids
|
|
885
|
-
});
|
|
886
|
-
this._loggedCacheEvents.add(setLogKey);
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
return obj;
|
|
890
|
-
} finally {
|
|
891
|
-
// Remove from pending loads
|
|
892
|
-
this._pendingLoads.delete(pendingKey);
|
|
893
|
-
}
|
|
894
|
-
})();
|
|
895
|
-
|
|
896
|
-
// Store the promise so other concurrent requests can await it
|
|
897
|
-
this._pendingLoads.set(pendingKey, loadPromise);
|
|
898
|
-
return await loadPromise;
|
|
1620
|
+
// Clear all cached objects
|
|
1621
|
+
var size = this._objectCache.size;
|
|
1622
|
+
this._objectCache.clear();
|
|
1623
|
+
this._loggedCacheEvents.clear();
|
|
1624
|
+
this._pendingLoads.clear();
|
|
899
1625
|
}
|
|
900
|
-
} catch (e) {
|
|
901
|
-
return this._handleError(e);
|
|
902
1626
|
}
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
/**
|
|
906
|
-
* Clears the object cache. Useful for cache invalidation.
|
|
907
|
-
* @param {string} type - Optional object type to clear. If not provided, clears all.
|
|
908
|
-
* @param {string} id - Optional object ID to clear. If not provided with type, clears all objects of that type.
|
|
909
|
-
*/
|
|
910
|
-
clearCache(type = null, id = null) {
|
|
911
|
-
if (type && id) {
|
|
912
|
-
// Clear specific object
|
|
913
|
-
const cacheKey = `${type}:${id}`;
|
|
914
|
-
const removed = this._objectCache.delete(cacheKey);
|
|
915
1627
|
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
// Clear related log tracking for this type
|
|
936
|
-
for (const logKey of this._loggedCacheEvents) {
|
|
937
|
-
if (logKey.includes(`${type}:`)) {
|
|
938
|
-
this._loggedCacheEvents.delete(logKey);
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
console.log('[AgentProviderSync] 🗑️ roboto.clearCache by type:', {
|
|
942
|
-
type,
|
|
943
|
-
removedCount
|
|
944
|
-
});
|
|
945
|
-
} else {
|
|
946
|
-
// Clear all cached objects
|
|
947
|
-
const size = this._objectCache.size;
|
|
948
|
-
this._objectCache.clear();
|
|
949
|
-
this._loggedCacheEvents.clear();
|
|
950
|
-
this._pendingLoads.clear();
|
|
951
|
-
console.log('[AgentProviderSync] 🗑️ roboto.clearCache all objects:', {
|
|
952
|
-
clearedCount: size
|
|
1628
|
+
/**
|
|
1629
|
+
* Gets cache status for debugging
|
|
1630
|
+
* @returns {Object} Cache status information
|
|
1631
|
+
*/
|
|
1632
|
+
}, {
|
|
1633
|
+
key: "getCacheStatus",
|
|
1634
|
+
value: function getCacheStatus() {
|
|
1635
|
+
var cacheEntries = Array.from(this._objectCache.entries()).map(function (_ref6) {
|
|
1636
|
+
var _obj$_internalData;
|
|
1637
|
+
var _ref7 = _slicedToArray(_ref6, 2),
|
|
1638
|
+
key = _ref7[0],
|
|
1639
|
+
obj = _ref7[1];
|
|
1640
|
+
return {
|
|
1641
|
+
key: key,
|
|
1642
|
+
id: obj.id,
|
|
1643
|
+
type: ((_obj$_internalData = obj._internalData) === null || _obj$_internalData === void 0 ? void 0 : _obj$_internalData.type) || 'unknown'
|
|
1644
|
+
};
|
|
953
1645
|
});
|
|
1646
|
+
var pendingLoads = Array.from(this._pendingLoads.keys());
|
|
1647
|
+
return {
|
|
1648
|
+
cacheSize: this._objectCache.size,
|
|
1649
|
+
pendingLoads: pendingLoads.length,
|
|
1650
|
+
loggedEvents: this._loggedCacheEvents.size,
|
|
1651
|
+
entries: cacheEntries,
|
|
1652
|
+
pendingKeys: pendingLoads
|
|
1653
|
+
};
|
|
954
1654
|
}
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
/**
|
|
958
|
-
* Gets cache status for debugging
|
|
959
|
-
* @returns {Object} Cache status information
|
|
960
|
-
*/
|
|
961
|
-
getCacheStatus() {
|
|
962
|
-
const cacheEntries = Array.from(this._objectCache.entries()).map(([key, obj]) => ({
|
|
963
|
-
key,
|
|
964
|
-
id: obj.id,
|
|
965
|
-
type: obj._internalData?.type || 'unknown'
|
|
966
|
-
}));
|
|
967
|
-
const pendingLoads = Array.from(this._pendingLoads.keys());
|
|
968
|
-
return {
|
|
969
|
-
cacheSize: this._objectCache.size,
|
|
970
|
-
pendingLoads: pendingLoads.length,
|
|
971
|
-
loggedEvents: this._loggedCacheEvents.size,
|
|
972
|
-
entries: cacheEntries,
|
|
973
|
-
pendingKeys: pendingLoads
|
|
974
|
-
};
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
/**
|
|
978
|
-
* Makes a POST request to a specific endpoint to run a task and handle progress updates.
|
|
979
|
-
*
|
|
980
|
-
* @param params.id (optional) IF the client is MONITORING the job with WS ClientMonitor,
|
|
981
|
-
* the client should generate a jobId and connect to the ClientMonitor
|
|
982
|
-
* BEFORE starting the job, to make sure no messages are missed -
|
|
983
|
-
* otherwise we'd have to delay the task start.
|
|
984
|
-
*
|
|
985
|
-
* @param {Object} params - The parameters to be sent in the POST request.
|
|
986
|
-
* @param {Object} callbacks - An object containing callback functions for progress and error handling.
|
|
987
|
-
*
|
|
988
|
-
* The function expects a response in the following format:
|
|
989
|
-
* {
|
|
990
|
-
* ok: boolean, // Indicates if the request was successful or not
|
|
991
|
-
* jobId: string, // The job identifier
|
|
992
|
-
* status: string // Can be 'RUNNING', 'DONE', or 'ERROR'
|
|
993
|
-
* }
|
|
994
|
-
*/
|
|
995
|
-
async runTask(params = {}, callbacks = {}) {
|
|
996
|
-
const {
|
|
997
|
-
onProgress,
|
|
998
|
-
onError,
|
|
999
|
-
onStopped,
|
|
1000
|
-
onWaiting,
|
|
1001
|
-
onDone
|
|
1002
|
-
} = callbacks;
|
|
1003
|
-
try {
|
|
1004
|
-
const response = await this.post('/task_service/runChain', params);
|
|
1005
|
-
|
|
1006
|
-
// Check if response and response.data are defined
|
|
1007
|
-
if (!response) {
|
|
1008
|
-
throw new Error('Invalid server response');
|
|
1009
|
-
}
|
|
1010
1655
|
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1656
|
+
/**
|
|
1657
|
+
* Makes a POST request to a specific endpoint to run a task and handle progress updates.
|
|
1658
|
+
*
|
|
1659
|
+
* @param params.id (optional) IF the client is MONITORING the job with WS ClientMonitor,
|
|
1660
|
+
* the client should generate a jobId and connect to the ClientMonitor
|
|
1661
|
+
* BEFORE starting the job, to make sure no messages are missed -
|
|
1662
|
+
* otherwise we'd have to delay the task start.
|
|
1663
|
+
*
|
|
1664
|
+
* @param {Object} params - The parameters to be sent in the POST request.
|
|
1665
|
+
* @param {Object} callbacks - An object containing callback functions for progress and error handling.
|
|
1666
|
+
*
|
|
1667
|
+
* The function expects a response in the following format:
|
|
1668
|
+
* {
|
|
1669
|
+
* ok: boolean, // Indicates if the request was successful or not
|
|
1670
|
+
* jobId: string, // The job identifier
|
|
1671
|
+
* status: string // Can be 'RUNNING', 'DONE', or 'ERROR'
|
|
1672
|
+
* }
|
|
1673
|
+
*/
|
|
1674
|
+
}, {
|
|
1675
|
+
key: "runTask",
|
|
1676
|
+
value: (function () {
|
|
1677
|
+
var _runTask = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
|
|
1678
|
+
var params,
|
|
1679
|
+
callbacks,
|
|
1680
|
+
onProgress,
|
|
1681
|
+
onError,
|
|
1682
|
+
onStopped,
|
|
1683
|
+
onWaiting,
|
|
1684
|
+
onDone,
|
|
1685
|
+
response,
|
|
1686
|
+
ok,
|
|
1687
|
+
jobId,
|
|
1688
|
+
status,
|
|
1689
|
+
message,
|
|
1690
|
+
output,
|
|
1691
|
+
errorResponse,
|
|
1692
|
+
_args25 = arguments;
|
|
1693
|
+
return _regeneratorRuntime().wrap(function _callee25$(_context25) {
|
|
1694
|
+
while (1) switch (_context25.prev = _context25.next) {
|
|
1695
|
+
case 0:
|
|
1696
|
+
params = _args25.length > 0 && _args25[0] !== undefined ? _args25[0] : {};
|
|
1697
|
+
callbacks = _args25.length > 1 && _args25[1] !== undefined ? _args25[1] : {};
|
|
1698
|
+
onProgress = callbacks.onProgress, onError = callbacks.onError, onStopped = callbacks.onStopped, onWaiting = callbacks.onWaiting, onDone = callbacks.onDone;
|
|
1699
|
+
_context25.prev = 3;
|
|
1700
|
+
_context25.next = 6;
|
|
1701
|
+
return this.post('/task_service/runChain', params);
|
|
1702
|
+
case 6:
|
|
1703
|
+
response = _context25.sent;
|
|
1704
|
+
if (response) {
|
|
1705
|
+
_context25.next = 9;
|
|
1706
|
+
break;
|
|
1707
|
+
}
|
|
1708
|
+
throw new Error('Invalid server response');
|
|
1709
|
+
case 9:
|
|
1710
|
+
// Validate response structure
|
|
1711
|
+
ok = response.ok, jobId = response.jobId, status = response.status, message = response.message, output = response.output;
|
|
1712
|
+
if (!(!ok || typeof jobId !== 'string' || typeof status !== 'string')) {
|
|
1713
|
+
_context25.next = 12;
|
|
1714
|
+
break;
|
|
1715
|
+
}
|
|
1716
|
+
throw new Error('Invalid response structure');
|
|
1717
|
+
case 12:
|
|
1718
|
+
// If the task is still in progress, start polling for updates
|
|
1719
|
+
if (status === 'RUNNING' || status === 'SCHEDULED' || status === 'QUEUED' || status === 'STOPPING') {
|
|
1720
|
+
this.pollTaskProgress(jobId, callbacks);
|
|
1721
|
+
}
|
|
1722
|
+
if (status === 'ERROR' && onError) {
|
|
1723
|
+
// Normalize error response to have consistent message/label at top level
|
|
1724
|
+
onError(this._normalizeErrorResponse(response));
|
|
1725
|
+
}
|
|
1726
|
+
if (status === 'STOPPED' && onStopped) {
|
|
1727
|
+
// Provide the current progress to the callback function
|
|
1728
|
+
onStopped(response);
|
|
1729
|
+
}
|
|
1730
|
+
if (status === 'WAITING' && onWaiting) {
|
|
1731
|
+
// Provide the current progress to the callback function
|
|
1732
|
+
onWaiting(response);
|
|
1733
|
+
}
|
|
1734
|
+
if (status === 'DONE' && onDone) {
|
|
1735
|
+
// Provide the current progress to the callback function
|
|
1736
|
+
//console.log('Finish (request) ',response); s
|
|
1737
|
+
onDone(response);
|
|
1738
|
+
}
|
|
1739
|
+
return _context25.abrupt("return", {
|
|
1740
|
+
ok: ok,
|
|
1741
|
+
jobId: jobId,
|
|
1742
|
+
status: status,
|
|
1743
|
+
message: message,
|
|
1744
|
+
output: output
|
|
1745
|
+
});
|
|
1746
|
+
case 20:
|
|
1747
|
+
_context25.prev = 20;
|
|
1748
|
+
_context25.t0 = _context25["catch"](3);
|
|
1749
|
+
// Standardize error format to match task response object
|
|
1750
|
+
// Support RbtError format with label and message
|
|
1751
|
+
errorResponse = {
|
|
1752
|
+
ok: false,
|
|
1753
|
+
jobId: null,
|
|
1754
|
+
status: 'ERROR',
|
|
1755
|
+
message: _context25.t0.message || _context25.t0.toString() || 'Unknown error',
|
|
1756
|
+
label: _context25.t0.label || _context25.t0.name || 'Error',
|
|
1757
|
+
output: {
|
|
1758
|
+
error: _context25.t0.message,
|
|
1759
|
+
label: _context25.t0.label,
|
|
1760
|
+
stack: _context25.t0.stack,
|
|
1761
|
+
originalError: _context25.t0
|
|
1762
|
+
}
|
|
1763
|
+
};
|
|
1764
|
+
if (typeof onError === 'function') {
|
|
1765
|
+
onError(errorResponse);
|
|
1766
|
+
} else {
|
|
1767
|
+
console.error('Error in runTask:', errorResponse.message);
|
|
1768
|
+
}
|
|
1769
|
+
return _context25.abrupt("return", errorResponse);
|
|
1770
|
+
case 25:
|
|
1771
|
+
case "end":
|
|
1772
|
+
return _context25.stop();
|
|
1773
|
+
}
|
|
1774
|
+
}, _callee25, this, [[3, 20]]);
|
|
1775
|
+
}));
|
|
1776
|
+
function runTask() {
|
|
1777
|
+
return _runTask.apply(this, arguments);
|
|
1043
1778
|
}
|
|
1044
|
-
return
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1779
|
+
return runTask;
|
|
1780
|
+
}())
|
|
1781
|
+
}, {
|
|
1782
|
+
key: "stopJob",
|
|
1783
|
+
value: function () {
|
|
1784
|
+
var _stopJob = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
|
|
1785
|
+
var params,
|
|
1786
|
+
callbacks,
|
|
1787
|
+
response,
|
|
1788
|
+
_args26 = arguments;
|
|
1789
|
+
return _regeneratorRuntime().wrap(function _callee26$(_context26) {
|
|
1790
|
+
while (1) switch (_context26.prev = _context26.next) {
|
|
1791
|
+
case 0:
|
|
1792
|
+
params = _args26.length > 0 && _args26[0] !== undefined ? _args26[0] : {};
|
|
1793
|
+
callbacks = _args26.length > 1 && _args26[1] !== undefined ? _args26[1] : {};
|
|
1794
|
+
_context26.prev = 2;
|
|
1795
|
+
_context26.next = 5;
|
|
1796
|
+
return this.post('/task_service/stopJob', params);
|
|
1797
|
+
case 5:
|
|
1798
|
+
response = _context26.sent;
|
|
1799
|
+
if (response) {
|
|
1800
|
+
_context26.next = 8;
|
|
1801
|
+
break;
|
|
1802
|
+
}
|
|
1803
|
+
throw new Error('Invalid server response');
|
|
1804
|
+
case 8:
|
|
1805
|
+
return _context26.abrupt("return", true);
|
|
1806
|
+
case 11:
|
|
1807
|
+
_context26.prev = 11;
|
|
1808
|
+
_context26.t0 = _context26["catch"](2);
|
|
1809
|
+
throw 'Error in stopJob';
|
|
1810
|
+
case 14:
|
|
1811
|
+
case "end":
|
|
1812
|
+
return _context26.stop();
|
|
1813
|
+
}
|
|
1814
|
+
}, _callee26, this, [[2, 11]]);
|
|
1815
|
+
}));
|
|
1816
|
+
function stopJob() {
|
|
1817
|
+
return _stopJob.apply(this, arguments);
|
|
1071
1818
|
}
|
|
1072
|
-
return
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1819
|
+
return stopJob;
|
|
1820
|
+
}()
|
|
1821
|
+
/**
|
|
1822
|
+
* Normalize error response to have consistent message/label at top level
|
|
1823
|
+
* Extracts from messages array if present (from chain execution)
|
|
1824
|
+
*/
|
|
1825
|
+
}, {
|
|
1826
|
+
key: "_normalizeErrorResponse",
|
|
1827
|
+
value: function _normalizeErrorResponse(response) {
|
|
1828
|
+
// If response already has message/label at top level and no messages array, return as-is
|
|
1829
|
+
if ((response.message || response.label) && !response.messages) {
|
|
1830
|
+
return response;
|
|
1081
1831
|
}
|
|
1082
|
-
return true;
|
|
1083
|
-
} catch (e) {
|
|
1084
|
-
throw 'Error in stopJob';
|
|
1085
|
-
}
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
/**
|
|
1089
|
-
* Normalize error response to have consistent message/label at top level
|
|
1090
|
-
* Extracts from messages array if present (from chain execution)
|
|
1091
|
-
*/
|
|
1092
|
-
_normalizeErrorResponse(response) {
|
|
1093
|
-
// If response already has message/label at top level and no messages array, return as-is
|
|
1094
|
-
if ((response.message || response.label) && !response.messages) {
|
|
1095
|
-
return response;
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
// Extract the most recent error from messages array
|
|
1099
|
-
if (response.messages && response.messages.length > 0) {
|
|
1100
|
-
const lastMessage = response.messages[response.messages.length - 1];
|
|
1101
|
-
return {
|
|
1102
|
-
...response,
|
|
1103
|
-
message: lastMessage.message || response.message || 'Unknown error',
|
|
1104
|
-
label: lastMessage.label || response.label || 'Error'
|
|
1105
|
-
};
|
|
1106
|
-
}
|
|
1107
1832
|
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
}
|
|
1115
|
-
|
|
1116
|
-
/**
|
|
1117
|
-
* Polls the progress of a long-running task.
|
|
1118
|
-
*
|
|
1119
|
-
* @param {string} jobId - The ID of the job to poll for progress.
|
|
1120
|
-
* @param {function} onProgress - Callback function that receives progress updates.
|
|
1121
|
-
*
|
|
1122
|
-
* The function periodically sends GET requests to check the task's progress
|
|
1123
|
-
* and reports back via the provided callback function . The polling stops when
|
|
1124
|
-
* the task is completed or an error occurs.
|
|
1125
|
-
*/
|
|
1126
|
-
async pollTaskProgress(jobId, callbacks) {
|
|
1127
|
-
const {
|
|
1128
|
-
onProgress,
|
|
1129
|
-
onError,
|
|
1130
|
-
onStopped,
|
|
1131
|
-
onWaiting,
|
|
1132
|
-
onDone,
|
|
1133
|
-
pollingInterval = 2000
|
|
1134
|
-
} = callbacks;
|
|
1135
|
-
try {
|
|
1136
|
-
const checkProgress = async () => {
|
|
1137
|
-
const response = await this.get(`/task_service/pollChainProgress`, {
|
|
1138
|
-
jobId: jobId
|
|
1833
|
+
// Extract the most recent error from messages array
|
|
1834
|
+
if (response.messages && response.messages.length > 0) {
|
|
1835
|
+
var lastMessage = response.messages[response.messages.length - 1];
|
|
1836
|
+
return _objectSpread(_objectSpread({}, response), {}, {
|
|
1837
|
+
message: lastMessage.message || response.message || 'Unknown error',
|
|
1838
|
+
label: lastMessage.label || response.label || 'Error'
|
|
1139
1839
|
});
|
|
1140
|
-
|
|
1141
|
-
// If the task is still in progress, start polling for updates
|
|
1142
|
-
if (response.status === 'DONE' && onDone) {
|
|
1143
|
-
// Provide the current progress to the callback function
|
|
1144
|
-
//console.log('Finish (progress) ',response);
|
|
1145
|
-
onDone(response);
|
|
1146
|
-
}
|
|
1147
|
-
if (response.status === 'ERROR' && onError) {
|
|
1148
|
-
// Normalize error response to have consistent message/label at top level
|
|
1149
|
-
onError(this._normalizeErrorResponse(response));
|
|
1150
|
-
}
|
|
1151
|
-
if (response.status === 'STOPPED' && onStopped) {
|
|
1152
|
-
// Provide the current progress to the callback function
|
|
1153
|
-
onStopped(response);
|
|
1154
|
-
}
|
|
1155
|
-
if (response.status === 'WAITING' && onWaiting) {
|
|
1156
|
-
// Provide the current progress to the callback function
|
|
1157
|
-
onWaiting(response);
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
// Provide the current progress to the callback function
|
|
1161
|
-
if (response.status == 'RUNNING' && onProgress) {
|
|
1162
|
-
onProgress(response);
|
|
1163
|
-
}
|
|
1164
|
-
|
|
1165
|
-
// Continue polling if the status is 'RUNNING' or STOPPING
|
|
1166
|
-
if (['RUNNING', 'STOPPING'].includes(response.status)) {
|
|
1167
|
-
setTimeout(checkProgress, pollingInterval); // Poll every 2 seconds
|
|
1168
|
-
}
|
|
1169
|
-
};
|
|
1170
|
-
checkProgress();
|
|
1171
|
-
} catch (e) {
|
|
1172
|
-
// Handle error based on your application's logic
|
|
1173
|
-
return this._handleError(e);
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
|
|
1177
|
-
/**
|
|
1178
|
-
* Performs a GET request to the specified endpoint.
|
|
1179
|
-
*
|
|
1180
|
-
* This method uses the Axios instance to make an authenticated GET request.
|
|
1181
|
-
* The `authtoken` stored in the class instance is included in the request headers
|
|
1182
|
-
* for authorization. It handles any errors and returns the response data.
|
|
1183
|
-
*
|
|
1184
|
-
* @param {string} endpoint - The endpoint URL to which the GET request is made.
|
|
1185
|
-
* @param {Object} [params={}] - Optional parameters to be sent with the request.
|
|
1186
|
-
* @returns {Promise<Object>} - The response data from the API.
|
|
1187
|
-
*/
|
|
1188
|
-
async get(endpoint, params = {}) {
|
|
1189
|
-
try {
|
|
1190
|
-
// Add the authToken to the headers
|
|
1191
|
-
const headers = {
|
|
1192
|
-
authtoken: this.authtoken
|
|
1193
|
-
};
|
|
1194
|
-
|
|
1195
|
-
// Make the GET request using Axios
|
|
1196
|
-
const response = await this.axios.get(endpoint, {
|
|
1197
|
-
params,
|
|
1198
|
-
headers
|
|
1199
|
-
});
|
|
1200
|
-
|
|
1201
|
-
// Check if the response is not okay
|
|
1202
|
-
if (response.data.ok === false) {
|
|
1203
|
-
return this._handleError(response);
|
|
1204
1840
|
}
|
|
1205
1841
|
|
|
1206
|
-
//
|
|
1207
|
-
return response
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
return this._handleError(e);
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
|
|
1214
|
-
/**
|
|
1215
|
-
* Performs a POST request to the specified endpoint.
|
|
1216
|
-
*
|
|
1217
|
-
* This method uses the Axios instance to make an authenticated POST request.
|
|
1218
|
-
* It includes the `authtoken` in the request headers for authorization. The method
|
|
1219
|
-
* sends the provided data as the request body. It handles any errors and returns
|
|
1220
|
-
* the response data.
|
|
1221
|
-
*
|
|
1222
|
-
* @param {string} endpoint - The endpoint URL to which the POST request is made.
|
|
1223
|
-
* @param {Object} [data={}] - Data to be sent in the body of the POST request.
|
|
1224
|
-
* @returns {Promise<Object>} - The response data from the API.
|
|
1225
|
-
*/
|
|
1226
|
-
async post(endpoint, data = {}) {
|
|
1227
|
-
try {
|
|
1228
|
-
// Add the authToken to the headers
|
|
1229
|
-
const headers = {
|
|
1230
|
-
authtoken: this.authtoken
|
|
1231
|
-
};
|
|
1232
|
-
|
|
1233
|
-
// Make the POST request using Axios
|
|
1234
|
-
const response = await this.axios.post(endpoint, data, {
|
|
1235
|
-
headers
|
|
1842
|
+
// Fallback: ensure we have at least message/label fields
|
|
1843
|
+
return _objectSpread(_objectSpread({}, response), {}, {
|
|
1844
|
+
message: response.message || 'Unknown error',
|
|
1845
|
+
label: response.label || 'Error'
|
|
1236
1846
|
});
|
|
1847
|
+
}
|
|
1237
1848
|
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1849
|
+
/**
|
|
1850
|
+
* Polls the progress of a long-running task.
|
|
1851
|
+
*
|
|
1852
|
+
* @param {string} jobId - The ID of the job to poll for progress.
|
|
1853
|
+
* @param {function} onProgress - Callback function that receives progress updates.
|
|
1854
|
+
*
|
|
1855
|
+
* The function periodically sends GET requests to check the task's progress
|
|
1856
|
+
* and reports back via the provided callback function . The polling stops when
|
|
1857
|
+
* the task is completed or an error occurs.
|
|
1858
|
+
*/
|
|
1859
|
+
}, {
|
|
1860
|
+
key: "pollTaskProgress",
|
|
1861
|
+
value: (function () {
|
|
1862
|
+
var _pollTaskProgress = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(jobId, callbacks) {
|
|
1863
|
+
var _this9 = this;
|
|
1864
|
+
var onProgress, onError, onStopped, onWaiting, onDone, _callbacks$pollingInt, pollingInterval, checkProgress;
|
|
1865
|
+
return _regeneratorRuntime().wrap(function _callee28$(_context28) {
|
|
1866
|
+
while (1) switch (_context28.prev = _context28.next) {
|
|
1867
|
+
case 0:
|
|
1868
|
+
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;
|
|
1869
|
+
_context28.prev = 1;
|
|
1870
|
+
checkProgress = /*#__PURE__*/function () {
|
|
1871
|
+
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
|
|
1872
|
+
var response;
|
|
1873
|
+
return _regeneratorRuntime().wrap(function _callee27$(_context27) {
|
|
1874
|
+
while (1) switch (_context27.prev = _context27.next) {
|
|
1875
|
+
case 0:
|
|
1876
|
+
_context27.next = 2;
|
|
1877
|
+
return _this9.get("/task_service/pollChainProgress", {
|
|
1878
|
+
jobId: jobId
|
|
1879
|
+
});
|
|
1880
|
+
case 2:
|
|
1881
|
+
response = _context27.sent;
|
|
1882
|
+
// If the task is still in progress, start polling for updates
|
|
1883
|
+
if (response.status === 'DONE' && onDone) {
|
|
1884
|
+
// Provide the current progress to the callback function
|
|
1885
|
+
//console.log('Finish (progress) ',response);
|
|
1886
|
+
onDone(response);
|
|
1887
|
+
}
|
|
1888
|
+
if (response.status === 'ERROR' && onError) {
|
|
1889
|
+
// Normalize error response to have consistent message/label at top level
|
|
1890
|
+
onError(_this9._normalizeErrorResponse(response));
|
|
1891
|
+
}
|
|
1892
|
+
if (response.status === 'STOPPED' && onStopped) {
|
|
1893
|
+
// Provide the current progress to the callback function
|
|
1894
|
+
onStopped(response);
|
|
1895
|
+
}
|
|
1896
|
+
if (response.status === 'WAITING' && onWaiting) {
|
|
1897
|
+
// Provide the current progress to the callback function
|
|
1898
|
+
onWaiting(response);
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
// Provide the current progress to the callback function
|
|
1902
|
+
if (response.status == 'RUNNING' && onProgress) {
|
|
1903
|
+
onProgress(response);
|
|
1904
|
+
}
|
|
1905
|
+
|
|
1906
|
+
// Continue polling if the status is 'RUNNING' or STOPPING
|
|
1907
|
+
if (['RUNNING', 'STOPPING'].includes(response.status)) {
|
|
1908
|
+
setTimeout(checkProgress, pollingInterval); // Poll every 2 seconds
|
|
1909
|
+
}
|
|
1910
|
+
case 9:
|
|
1911
|
+
case "end":
|
|
1912
|
+
return _context27.stop();
|
|
1913
|
+
}
|
|
1914
|
+
}, _callee27);
|
|
1915
|
+
}));
|
|
1916
|
+
return function checkProgress() {
|
|
1917
|
+
return _ref8.apply(this, arguments);
|
|
1918
|
+
};
|
|
1919
|
+
}();
|
|
1920
|
+
checkProgress();
|
|
1921
|
+
_context28.next = 9;
|
|
1922
|
+
break;
|
|
1923
|
+
case 6:
|
|
1924
|
+
_context28.prev = 6;
|
|
1925
|
+
_context28.t0 = _context28["catch"](1);
|
|
1926
|
+
return _context28.abrupt("return", this._handleError(_context28.t0));
|
|
1927
|
+
case 9:
|
|
1928
|
+
case "end":
|
|
1929
|
+
return _context28.stop();
|
|
1930
|
+
}
|
|
1931
|
+
}, _callee28, this, [[1, 6]]);
|
|
1932
|
+
}));
|
|
1933
|
+
function pollTaskProgress(_x16, _x17) {
|
|
1934
|
+
return _pollTaskProgress.apply(this, arguments);
|
|
1241
1935
|
}
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1936
|
+
return pollTaskProgress;
|
|
1937
|
+
}()
|
|
1938
|
+
/**
|
|
1939
|
+
* Performs a GET request to the specified endpoint.
|
|
1940
|
+
*
|
|
1941
|
+
* This method uses the Axios instance to make an authenticated GET request.
|
|
1942
|
+
* The `authtoken` stored in the class instance is included in the request headers
|
|
1943
|
+
* for authorization. It handles any errors and returns the response data.
|
|
1944
|
+
*
|
|
1945
|
+
* @param {string} endpoint - The endpoint URL to which the GET request is made.
|
|
1946
|
+
* @param {Object} [params={}] - Optional parameters to be sent with the request.
|
|
1947
|
+
* @returns {Promise<Object>} - The response data from the API.
|
|
1948
|
+
*/
|
|
1949
|
+
)
|
|
1950
|
+
}, {
|
|
1951
|
+
key: "get",
|
|
1952
|
+
value: (function () {
|
|
1953
|
+
var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(endpoint) {
|
|
1954
|
+
var params,
|
|
1955
|
+
headers,
|
|
1956
|
+
response,
|
|
1957
|
+
_args29 = arguments;
|
|
1958
|
+
return _regeneratorRuntime().wrap(function _callee29$(_context29) {
|
|
1959
|
+
while (1) switch (_context29.prev = _context29.next) {
|
|
1960
|
+
case 0:
|
|
1961
|
+
params = _args29.length > 1 && _args29[1] !== undefined ? _args29[1] : {};
|
|
1962
|
+
_context29.prev = 1;
|
|
1963
|
+
// Add the authToken to the headers
|
|
1964
|
+
headers = {
|
|
1965
|
+
authtoken: this.authtoken
|
|
1966
|
+
}; // Make the GET request using Axios
|
|
1967
|
+
_context29.next = 5;
|
|
1968
|
+
return this.axios.get(endpoint, {
|
|
1969
|
+
params: params,
|
|
1970
|
+
headers: headers
|
|
1971
|
+
});
|
|
1972
|
+
case 5:
|
|
1973
|
+
response = _context29.sent;
|
|
1974
|
+
if (!(response.data.ok === false)) {
|
|
1975
|
+
_context29.next = 8;
|
|
1976
|
+
break;
|
|
1977
|
+
}
|
|
1978
|
+
return _context29.abrupt("return", this._handleError(response));
|
|
1979
|
+
case 8:
|
|
1980
|
+
return _context29.abrupt("return", response.data);
|
|
1981
|
+
case 11:
|
|
1982
|
+
_context29.prev = 11;
|
|
1983
|
+
_context29.t0 = _context29["catch"](1);
|
|
1984
|
+
return _context29.abrupt("return", this._handleError(_context29.t0));
|
|
1985
|
+
case 14:
|
|
1986
|
+
case "end":
|
|
1987
|
+
return _context29.stop();
|
|
1988
|
+
}
|
|
1989
|
+
}, _callee29, this, [[1, 11]]);
|
|
1990
|
+
}));
|
|
1991
|
+
function get(_x18) {
|
|
1992
|
+
return _get.apply(this, arguments);
|
|
1993
|
+
}
|
|
1994
|
+
return get;
|
|
1995
|
+
}()
|
|
1996
|
+
/**
|
|
1997
|
+
* Performs a POST request to the specified endpoint.
|
|
1998
|
+
*
|
|
1999
|
+
* This method uses the Axios instance to make an authenticated POST request.
|
|
2000
|
+
* It includes the `authtoken` in the request headers for authorization. The method
|
|
2001
|
+
* sends the provided data as the request body. It handles any errors and returns
|
|
2002
|
+
* the response data.
|
|
2003
|
+
*
|
|
2004
|
+
* @param {string} endpoint - The endpoint URL to which the POST request is made.
|
|
2005
|
+
* @param {Object} [data={}] - Data to be sent in the body of the POST request.
|
|
2006
|
+
* @returns {Promise<Object>} - The response data from the API.
|
|
2007
|
+
*/
|
|
2008
|
+
)
|
|
2009
|
+
}, {
|
|
2010
|
+
key: "post",
|
|
2011
|
+
value: (function () {
|
|
2012
|
+
var _post = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(endpoint) {
|
|
2013
|
+
var data,
|
|
2014
|
+
headers,
|
|
2015
|
+
response,
|
|
2016
|
+
_args30 = arguments;
|
|
2017
|
+
return _regeneratorRuntime().wrap(function _callee30$(_context30) {
|
|
2018
|
+
while (1) switch (_context30.prev = _context30.next) {
|
|
2019
|
+
case 0:
|
|
2020
|
+
data = _args30.length > 1 && _args30[1] !== undefined ? _args30[1] : {};
|
|
2021
|
+
_context30.prev = 1;
|
|
2022
|
+
// Add the authToken to the headers
|
|
2023
|
+
headers = {
|
|
2024
|
+
authtoken: this.authtoken
|
|
2025
|
+
}; // Make the POST request using Axios
|
|
2026
|
+
_context30.next = 5;
|
|
2027
|
+
return this.axios.post(endpoint, data, {
|
|
2028
|
+
headers: headers
|
|
2029
|
+
});
|
|
2030
|
+
case 5:
|
|
2031
|
+
response = _context30.sent;
|
|
2032
|
+
if (!(response.data.ok === false)) {
|
|
2033
|
+
_context30.next = 8;
|
|
2034
|
+
break;
|
|
2035
|
+
}
|
|
2036
|
+
return _context30.abrupt("return", this._handleError(response));
|
|
2037
|
+
case 8:
|
|
2038
|
+
return _context30.abrupt("return", response.data);
|
|
2039
|
+
case 11:
|
|
2040
|
+
_context30.prev = 11;
|
|
2041
|
+
_context30.t0 = _context30["catch"](1);
|
|
2042
|
+
return _context30.abrupt("return", this._handleError(_context30.t0));
|
|
2043
|
+
case 14:
|
|
2044
|
+
case "end":
|
|
2045
|
+
return _context30.stop();
|
|
2046
|
+
}
|
|
2047
|
+
}, _callee30, this, [[1, 11]]);
|
|
2048
|
+
}));
|
|
2049
|
+
function post(_x19) {
|
|
2050
|
+
return _post.apply(this, arguments);
|
|
2051
|
+
}
|
|
2052
|
+
return post;
|
|
2053
|
+
}())
|
|
2054
|
+
}, {
|
|
2055
|
+
key: "setErrorHandler",
|
|
2056
|
+
value: function setErrorHandler(customErrorHandler) {
|
|
2057
|
+
this.customErrorHandler = customErrorHandler;
|
|
1258
2058
|
}
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
2059
|
+
}, {
|
|
2060
|
+
key: "_handleError",
|
|
2061
|
+
value: function _handleError(err) {
|
|
2062
|
+
// Invoke the custom error handler if provided
|
|
2063
|
+
if (this.customErrorHandler) {
|
|
2064
|
+
var res = this.customErrorHandler(err);
|
|
2065
|
+
if (res) return;
|
|
1266
2066
|
}
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
2067
|
+
if (_lodash["default"].isObject(err) && _lodash["default"].get(err, 'response')) {
|
|
2068
|
+
if (err.response) {}
|
|
2069
|
+
var msg = _lodash["default"].get(err, 'response.data.message', 'Error in API response');
|
|
2070
|
+
if (msg.key) {
|
|
2071
|
+
//throw new Error(msg.key);
|
|
2072
|
+
throw {
|
|
2073
|
+
message: msg.key
|
|
2074
|
+
};
|
|
2075
|
+
} else {
|
|
2076
|
+
//throw new Error(msg);
|
|
2077
|
+
throw {
|
|
2078
|
+
message: msg
|
|
2079
|
+
};
|
|
2080
|
+
}
|
|
1273
2081
|
} else {
|
|
1274
|
-
//throw new Error(
|
|
2082
|
+
//throw new Error(err.message || 'Unknown error');
|
|
1275
2083
|
throw {
|
|
1276
|
-
|
|
2084
|
+
code: err.code,
|
|
2085
|
+
message: err.message
|
|
2086
|
+
} || {
|
|
2087
|
+
message: err
|
|
2088
|
+
} || {
|
|
2089
|
+
message: 'Unknown error'
|
|
1277
2090
|
};
|
|
1278
2091
|
}
|
|
1279
|
-
} else {
|
|
1280
|
-
//throw new Error(err.message || 'Unknown error');
|
|
1281
|
-
throw {
|
|
1282
|
-
code: err.code,
|
|
1283
|
-
message: err.message
|
|
1284
|
-
} || {
|
|
1285
|
-
message: err
|
|
1286
|
-
} || {
|
|
1287
|
-
message: 'Unknown error'
|
|
1288
|
-
};
|
|
1289
2092
|
}
|
|
1290
|
-
}
|
|
1291
|
-
|
|
2093
|
+
}]);
|
|
2094
|
+
return RbtApi;
|
|
2095
|
+
}();
|