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