roboto-js 1.8.3 → 1.8.4
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/dist/cjs/rbt_api.cjs +33 -5
- package/dist/esm/rbt_api.js +33 -5
- package/package.json +1 -1
- package/src/rbt_api.js +33 -5
- package/dist/cookie_storage_adaptor.js +0 -415
- package/dist/index.js +0 -573
- package/dist/rbt_api.js +0 -2074
- package/dist/rbt_file.js +0 -223
- package/dist/rbt_metrics_api.js +0 -200
- package/dist/rbt_object.js +0 -1110
- package/dist/rbt_user.js +0 -235
package/dist/rbt_object.js
DELETED
|
@@ -1,1110 +0,0 @@
|
|
|
1
|
-
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
2
|
-
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."); }
|
|
3
|
-
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; } }
|
|
4
|
-
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
5
|
-
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; } } }; }
|
|
6
|
-
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 }; })(); }
|
|
7
|
-
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); }
|
|
8
|
-
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); }
|
|
9
|
-
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); }); }; }
|
|
10
|
-
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
11
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
12
|
-
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; } }
|
|
13
|
-
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
14
|
-
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
15
|
-
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; }
|
|
16
|
-
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); }
|
|
17
|
-
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; }
|
|
18
|
-
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; }
|
|
19
|
-
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; }
|
|
20
|
-
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
21
|
-
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); } }
|
|
22
|
-
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
23
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
24
|
-
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); }
|
|
25
|
-
import _ from 'lodash';
|
|
26
|
-
var RbtObject = /*#__PURE__*/function () {
|
|
27
|
-
function RbtObject(record, axiosInstance) {
|
|
28
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
29
|
-
_classCallCheck(this, RbtObject);
|
|
30
|
-
this._axios = axiosInstance;
|
|
31
|
-
this._internalData = record;
|
|
32
|
-
this.isRbtObject = true;
|
|
33
|
-
this.id = record.id;
|
|
34
|
-
this.id_revision = record.id_revision;
|
|
35
|
-
this.rpcMeta = record.rpcMeta || {
|
|
36
|
-
changes: [],
|
|
37
|
-
isNew: options.isNew || record.revision == 0 || false
|
|
38
|
-
};
|
|
39
|
-
if (record.data) {
|
|
40
|
-
this._data = this._deepUnpackJson(record.data);
|
|
41
|
-
} else {
|
|
42
|
-
this._data = record.dataJson ? this._deepUnpackJson(record.dataJson) : {};
|
|
43
|
-
}
|
|
44
|
-
if (options.websocketClient && this.id && options.enableRealtime) {
|
|
45
|
-
this._realtime = true;
|
|
46
|
-
this._ws = options.websocketClient;
|
|
47
|
-
this._subscribeToRealtime(this._ws);
|
|
48
|
-
} else if (options.websocketClient && this.id) {
|
|
49
|
-
// Store websocket client for potential later use, but don't auto-subscribe
|
|
50
|
-
this._ws = options.websocketClient;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// If enableRealtime is requested but no websocketClient provided, try to initialize lazily
|
|
54
|
-
if (options.enableRealtime && this.id && !this._realtime) {
|
|
55
|
-
this._initRealtime();
|
|
56
|
-
}
|
|
57
|
-
this._eventHandlers = {
|
|
58
|
-
change: [],
|
|
59
|
-
save: []
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// Debounce properties for WebSocket broadcasting
|
|
63
|
-
this._broadcastDebounceTimer = null;
|
|
64
|
-
this._pendingBroadcasts = new Map(); // path -> value
|
|
65
|
-
}
|
|
66
|
-
return _createClass(RbtObject, [{
|
|
67
|
-
key: "get",
|
|
68
|
-
value: function get(path) {
|
|
69
|
-
return _.get(this._data, path);
|
|
70
|
-
}
|
|
71
|
-
}, {
|
|
72
|
-
key: "getData",
|
|
73
|
-
value: function getData() {
|
|
74
|
-
var _this = this;
|
|
75
|
-
var keys = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
76
|
-
// Check if keys are provided
|
|
77
|
-
if (keys && Array.isArray(keys)) {
|
|
78
|
-
// Return an object with only the specified keys
|
|
79
|
-
return keys.reduce(function (result, key) {
|
|
80
|
-
// Use lodash.get to handle deep key paths
|
|
81
|
-
var value = _.get(_this._data, key);
|
|
82
|
-
// If the value exists, add it to the result object using the key path as the property name
|
|
83
|
-
if (value !== undefined) {
|
|
84
|
-
// Create nested structure based on the key path
|
|
85
|
-
_.set(result, key, value);
|
|
86
|
-
}
|
|
87
|
-
return result;
|
|
88
|
-
}, {});
|
|
89
|
-
} else {
|
|
90
|
-
// Return a shallow copy of the full data if no keys are provided
|
|
91
|
-
return _objectSpread({}, this._data);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}, {
|
|
95
|
-
key: "_addChange",
|
|
96
|
-
value: function _addChange(path) {
|
|
97
|
-
// Ensure no duplicate paths
|
|
98
|
-
if (!this.rpcMeta.changes.includes(path)) {
|
|
99
|
-
this.rpcMeta.changes.push(path);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}, {
|
|
103
|
-
key: "set",
|
|
104
|
-
value: function set(path, value) {
|
|
105
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
106
|
-
var currentValue = _.get(this._data, path); // Fetch current value at deep path
|
|
107
|
-
|
|
108
|
-
if (options.merge) {
|
|
109
|
-
var mergedValue = _.mergeWith({}, currentValue, value, function (objValue, srcValue) {
|
|
110
|
-
if (srcValue === undefined) {
|
|
111
|
-
return undefined; // Indicate to delete when merging
|
|
112
|
-
}
|
|
113
|
-
if (_.isArray(objValue)) {
|
|
114
|
-
return srcValue; // Customize merging behavior for arrays
|
|
115
|
-
}
|
|
116
|
-
// Handle null, 0, and "" explicitly
|
|
117
|
-
if (srcValue === null || srcValue === 0 || srcValue === "") {
|
|
118
|
-
return srcValue;
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
// Process merged object to remove any keys set explicitly to undefined
|
|
122
|
-
Object.keys(mergedValue).forEach(function (key) {
|
|
123
|
-
if (mergedValue[key] === undefined) {
|
|
124
|
-
_.unset(mergedValue, key);
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
if (!_.isEqual(currentValue, mergedValue)) {
|
|
128
|
-
_.set(this._data, path, mergedValue); // Set the merged value at the deep path
|
|
129
|
-
this._addChange(path);
|
|
130
|
-
// Trigger local change events for any registered handlers
|
|
131
|
-
this._trigger('change', {
|
|
132
|
-
path: path,
|
|
133
|
-
value: mergedValue,
|
|
134
|
-
options: options
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
} else {
|
|
138
|
-
// If value is undefined and not merging, delete the key
|
|
139
|
-
if (value === undefined) {
|
|
140
|
-
_.unset(this._data, path);
|
|
141
|
-
this._addChange(path);
|
|
142
|
-
// Trigger local change events for any registered handlers
|
|
143
|
-
this._trigger('change', {
|
|
144
|
-
path: path,
|
|
145
|
-
value: undefined,
|
|
146
|
-
options: options
|
|
147
|
-
});
|
|
148
|
-
} else if (!_.isEqual(currentValue, value)) {
|
|
149
|
-
_.set(this._data, path, value); // Set the value directly at the deep path
|
|
150
|
-
this._addChange(path);
|
|
151
|
-
this._broadcastChange(path, value);
|
|
152
|
-
// Trigger local change events for any registered handlers
|
|
153
|
-
this._trigger('change', {
|
|
154
|
-
path: path,
|
|
155
|
-
value: value,
|
|
156
|
-
options: options
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}, {
|
|
162
|
-
key: "setData",
|
|
163
|
-
value: function setData(newData) {
|
|
164
|
-
var _this2 = this;
|
|
165
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
166
|
-
if (_typeof(newData) !== 'object' || newData === null) {
|
|
167
|
-
throw new Error('setData expects an object');
|
|
168
|
-
}
|
|
169
|
-
var _options$merge = options.merge,
|
|
170
|
-
merge = _options$merge === void 0 ? false : _options$merge;
|
|
171
|
-
Object.keys(newData).forEach(function (path) {
|
|
172
|
-
var currentValue = _.get(_this2._data, path);
|
|
173
|
-
var newValue = newData[path];
|
|
174
|
-
if (merge && _.isObject(currentValue) && _.isObject(newValue)) {
|
|
175
|
-
var mergedValue = _.mergeWith({}, currentValue, newValue, function (objValue, srcValue) {
|
|
176
|
-
if (_.isArray(srcValue)) {
|
|
177
|
-
return _toConsumableArray(srcValue); // Customize merging behavior for arrays
|
|
178
|
-
}
|
|
179
|
-
// Handle null, 0, and "" explicitly
|
|
180
|
-
if (srcValue === null || srcValue === 0 || srcValue === "") {
|
|
181
|
-
return srcValue;
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
if (!_.isEqual(currentValue, mergedValue)) {
|
|
185
|
-
_.set(_this2._data, path, mergedValue);
|
|
186
|
-
_this2._addChange(path);
|
|
187
|
-
// Trigger change event for this path
|
|
188
|
-
_this2._trigger('change', {
|
|
189
|
-
path: path,
|
|
190
|
-
value: mergedValue,
|
|
191
|
-
options: options
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
} else if (!_.isEqual(currentValue, newValue)) {
|
|
195
|
-
_.setWith(_this2._data, path, newValue, function (nsValue, key, nsObject, nsPath) {
|
|
196
|
-
if (key === nsPath.split('.').pop() && !_.has(nsObject, key)) {
|
|
197
|
-
return nsObject[key] = {}; // Create any missing parts of the path as plain objects
|
|
198
|
-
}
|
|
199
|
-
return nsValue;
|
|
200
|
-
});
|
|
201
|
-
_this2._addChange(path);
|
|
202
|
-
// Trigger change event for this path
|
|
203
|
-
_this2._trigger('change', {
|
|
204
|
-
path: path,
|
|
205
|
-
value: newValue,
|
|
206
|
-
options: options
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
//
|
|
213
|
-
// For Arrays
|
|
214
|
-
//
|
|
215
|
-
}, {
|
|
216
|
-
key: "setAppend",
|
|
217
|
-
value: function () {
|
|
218
|
-
var _setAppend = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(key, value) {
|
|
219
|
-
var options,
|
|
220
|
-
existingValue,
|
|
221
|
-
valuesToAdd,
|
|
222
|
-
mergedValues,
|
|
223
|
-
_args = arguments;
|
|
224
|
-
return _regenerator().w(function (_context) {
|
|
225
|
-
while (1) switch (_context.n) {
|
|
226
|
-
case 0:
|
|
227
|
-
options = _args.length > 2 && _args[2] !== undefined ? _args[2] : {};
|
|
228
|
-
existingValue = this.get(key) || []; // Get the existing value or default to an empty array
|
|
229
|
-
if (!Array.isArray(existingValue)) {
|
|
230
|
-
existingValue = []; // Ensure existingValue is an array if not already
|
|
231
|
-
}
|
|
232
|
-
valuesToAdd = Array.isArray(value) ? value : [value]; // Convert value to an array if it's not one
|
|
233
|
-
// Combine existingValue and valuesToAdd, filtering out duplicates
|
|
234
|
-
mergedValues = Array.from(new Set([].concat(_toConsumableArray(existingValue), _toConsumableArray(valuesToAdd))));
|
|
235
|
-
this.set(key, mergedValues, options); // Set the updated array back to the user data
|
|
236
|
-
case 1:
|
|
237
|
-
return _context.a(2);
|
|
238
|
-
}
|
|
239
|
-
}, _callee, this);
|
|
240
|
-
}));
|
|
241
|
-
function setAppend(_x, _x2) {
|
|
242
|
-
return _setAppend.apply(this, arguments);
|
|
243
|
-
}
|
|
244
|
-
return setAppend;
|
|
245
|
-
}()
|
|
246
|
-
}, {
|
|
247
|
-
key: "setRemove",
|
|
248
|
-
value: function () {
|
|
249
|
-
var _setRemove = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(key, value) {
|
|
250
|
-
var options,
|
|
251
|
-
existingValue,
|
|
252
|
-
valuesToRemove,
|
|
253
|
-
filteredValues,
|
|
254
|
-
_args2 = arguments;
|
|
255
|
-
return _regenerator().w(function (_context2) {
|
|
256
|
-
while (1) switch (_context2.n) {
|
|
257
|
-
case 0:
|
|
258
|
-
options = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {};
|
|
259
|
-
existingValue = this.get(key) || []; // Get the existing value or default to an empty array
|
|
260
|
-
if (Array.isArray(existingValue)) {
|
|
261
|
-
_context2.n = 1;
|
|
262
|
-
break;
|
|
263
|
-
}
|
|
264
|
-
return _context2.a(2);
|
|
265
|
-
case 1:
|
|
266
|
-
valuesToRemove = Array.isArray(value) ? value : [value]; // Convert value to an array if it's not one
|
|
267
|
-
// Filter out the values to remove from the existing value array
|
|
268
|
-
filteredValues = existingValue.filter(function (item) {
|
|
269
|
-
return !valuesToRemove.includes(item);
|
|
270
|
-
});
|
|
271
|
-
this.set(key, filteredValues); // Set the updated array back to the user data
|
|
272
|
-
case 2:
|
|
273
|
-
return _context2.a(2);
|
|
274
|
-
}
|
|
275
|
-
}, _callee2, this);
|
|
276
|
-
}));
|
|
277
|
-
function setRemove(_x3, _x4) {
|
|
278
|
-
return _setRemove.apply(this, arguments);
|
|
279
|
-
}
|
|
280
|
-
return setRemove;
|
|
281
|
-
}()
|
|
282
|
-
}, {
|
|
283
|
-
key: "getMetaData",
|
|
284
|
-
value: function getMetaData() {
|
|
285
|
-
var meta = {
|
|
286
|
-
timeCreated: this._internalData.timeCreated,
|
|
287
|
-
timeModified: this._internalData.timeModified,
|
|
288
|
-
timeDeleted: this._internalData.timeDeleted,
|
|
289
|
-
revision: this._internalData.revision
|
|
290
|
-
};
|
|
291
|
-
return meta;
|
|
292
|
-
}
|
|
293
|
-
}, {
|
|
294
|
-
key: "toRecord",
|
|
295
|
-
value: function toRecord() {
|
|
296
|
-
return _objectSpread(_objectSpread({}, this._internalData), {}, {
|
|
297
|
-
dataJson: JSON.stringify(this._data),
|
|
298
|
-
rpcMeta: this.rpcMeta
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
}, {
|
|
302
|
-
key: "toDeltaRecord",
|
|
303
|
-
value: function toDeltaRecord() {
|
|
304
|
-
var changes = this.rpcMeta.changes;
|
|
305
|
-
|
|
306
|
-
// Initialize deltaData as an empty object
|
|
307
|
-
var sourceData = this._data;
|
|
308
|
-
var deltaData = {};
|
|
309
|
-
|
|
310
|
-
// Populate deltaData only with keys specified in changes
|
|
311
|
-
changes.forEach(function (path) {
|
|
312
|
-
// default value explicitly set to undefined
|
|
313
|
-
var value = _.get(sourceData, path, undefined);
|
|
314
|
-
// Use _.set to ensure nested keys are correctly assigned
|
|
315
|
-
_.set(deltaData, path, value);
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
// mark as delta
|
|
319
|
-
this.rpcMeta.delta = true;
|
|
320
|
-
var clonedData = _.cloneDeep(this._internalData);
|
|
321
|
-
clonedData.data = deltaData;
|
|
322
|
-
return _objectSpread(_objectSpread({}, clonedData), {}, {
|
|
323
|
-
dataJson: JSON.stringify(deltaData),
|
|
324
|
-
rpcMeta: this.rpcMeta
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
}, {
|
|
328
|
-
key: "clone",
|
|
329
|
-
value: function clone() {
|
|
330
|
-
// Create a deep copy of the current object's data
|
|
331
|
-
var clonedData = _.cloneDeep(this._internalData);
|
|
332
|
-
|
|
333
|
-
// Reset unique identifiers to ensure a new ID is generated upon saving
|
|
334
|
-
delete clonedData.id;
|
|
335
|
-
delete clonedData.id_revision;
|
|
336
|
-
delete clonedData.rpcMeta;
|
|
337
|
-
if (clonedData.data) {
|
|
338
|
-
delete clonedData.data.id;
|
|
339
|
-
delete clonedData.data.id_revision;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
// Create a new instance of RbtObject with the cloned data
|
|
343
|
-
var clonedObject = new RbtObject(clonedData, this._axios, {
|
|
344
|
-
isNew: true
|
|
345
|
-
});
|
|
346
|
-
return clonedObject;
|
|
347
|
-
}
|
|
348
|
-
}, {
|
|
349
|
-
key: "save",
|
|
350
|
-
value: function () {
|
|
351
|
-
var _save = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
|
|
352
|
-
var _response$data, _response$data2, record, response, _e$response, _t;
|
|
353
|
-
return _regenerator().w(function (_context3) {
|
|
354
|
-
while (1) switch (_context3.p = _context3.n) {
|
|
355
|
-
case 0:
|
|
356
|
-
if (this._internalData.type) {
|
|
357
|
-
_context3.n = 1;
|
|
358
|
-
break;
|
|
359
|
-
}
|
|
360
|
-
throw new Error('Cannot save object without type');
|
|
361
|
-
case 1:
|
|
362
|
-
_context3.p = 1;
|
|
363
|
-
if (this.rpcMeta.isNew) {
|
|
364
|
-
record = this.toRecord();
|
|
365
|
-
} else {
|
|
366
|
-
record = this.toDeltaRecord();
|
|
367
|
-
}
|
|
368
|
-
_context3.n = 2;
|
|
369
|
-
return this._axios.post('/object_service/saveObject', [record]);
|
|
370
|
-
case 2:
|
|
371
|
-
response = _context3.v;
|
|
372
|
-
if (!(response.data.ok === false)) {
|
|
373
|
-
_context3.n = 3;
|
|
374
|
-
break;
|
|
375
|
-
}
|
|
376
|
-
throw new Error(response.data.message);
|
|
377
|
-
case 3:
|
|
378
|
-
if (!(((_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.result) == 'NO_CHANGES')) {
|
|
379
|
-
_context3.n = 4;
|
|
380
|
-
break;
|
|
381
|
-
}
|
|
382
|
-
this.rpcMeta.isNew = false;
|
|
383
|
-
return _context3.a(2, this);
|
|
384
|
-
case 4:
|
|
385
|
-
if ((_response$data2 = response.data) !== null && _response$data2 !== void 0 && _response$data2.newData) {
|
|
386
|
-
// apply new incoming data
|
|
387
|
-
this.setData(response.newData);
|
|
388
|
-
}
|
|
389
|
-
this.id = response.data.id;
|
|
390
|
-
this.id_revision = response.data.id_revision;
|
|
391
|
-
this.type = response.data.type;
|
|
392
|
-
this.rpcMeta.isNew = false;
|
|
393
|
-
return _context3.a(2, this);
|
|
394
|
-
case 5:
|
|
395
|
-
_context3.p = 5;
|
|
396
|
-
_t = _context3.v;
|
|
397
|
-
console.log('RbtObject.save.error:', _t === null || _t === void 0 || (_e$response = _t.response) === null || _e$response === void 0 ? void 0 : _e$response.data);
|
|
398
|
-
this._error = _t;
|
|
399
|
-
//console.log(e.response.data);
|
|
400
|
-
throw _t;
|
|
401
|
-
case 6:
|
|
402
|
-
return _context3.a(2);
|
|
403
|
-
}
|
|
404
|
-
}, _callee3, this, [[1, 5]]);
|
|
405
|
-
}));
|
|
406
|
-
function save() {
|
|
407
|
-
return _save.apply(this, arguments);
|
|
408
|
-
}
|
|
409
|
-
return save;
|
|
410
|
-
}()
|
|
411
|
-
/**
|
|
412
|
-
* Grants access to this object for specific users and/or user groups.
|
|
413
|
-
* Updates the IAC (Identity and Access Control) permissions.
|
|
414
|
-
*
|
|
415
|
-
* @param {Object} options - Access grant options
|
|
416
|
-
* @param {string[]} [options.userIds=[]] - Array of user IDs to grant read access
|
|
417
|
-
* @param {string[]} [options.groupIds=[]] - Array of user group IDs to grant read access
|
|
418
|
-
* @param {boolean} [options.write=false] - If true, grants write access instead of read access
|
|
419
|
-
* @param {boolean} [options.replace=false] - If true, replaces existing grants; if false, merges with existing
|
|
420
|
-
* @param {boolean} [options.save=true] - If true, automatically saves the object after updating permissions
|
|
421
|
-
* @returns {Promise<RbtObject>} - Returns this object (saved if options.save is true)
|
|
422
|
-
*
|
|
423
|
-
* @example
|
|
424
|
-
* // Grant read access to specific users
|
|
425
|
-
* await myObject.grantAccess({
|
|
426
|
-
* userIds: ['user123', 'user456']
|
|
427
|
-
* });
|
|
428
|
-
*
|
|
429
|
-
* @example
|
|
430
|
-
* // Grant read access to user groups
|
|
431
|
-
* await myObject.grantAccess({
|
|
432
|
-
* groupIds: ['grpRngAccount', 'grpAdmins']
|
|
433
|
-
* });
|
|
434
|
-
*
|
|
435
|
-
* @example
|
|
436
|
-
* // Grant write access to users and groups
|
|
437
|
-
* await myObject.grantAccess({
|
|
438
|
-
* userIds: ['user123'],
|
|
439
|
-
* groupIds: ['grpAdmins'],
|
|
440
|
-
* write: true
|
|
441
|
-
* });
|
|
442
|
-
*
|
|
443
|
-
* @example
|
|
444
|
-
* // Replace existing permissions instead of merging
|
|
445
|
-
* await myObject.grantAccess({
|
|
446
|
-
* userIds: ['user123'],
|
|
447
|
-
* replace: true
|
|
448
|
-
* });
|
|
449
|
-
*
|
|
450
|
-
* @example
|
|
451
|
-
* // Update permissions without auto-saving
|
|
452
|
-
* await myObject.grantAccess({
|
|
453
|
-
* userIds: ['user123'],
|
|
454
|
-
* save: false
|
|
455
|
-
* });
|
|
456
|
-
* // ... make other changes ...
|
|
457
|
-
* await myObject.save();
|
|
458
|
-
*/
|
|
459
|
-
}, {
|
|
460
|
-
key: "grantAccess",
|
|
461
|
-
value: (function () {
|
|
462
|
-
var _grantAccess = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
|
|
463
|
-
var options,
|
|
464
|
-
_options$userIds,
|
|
465
|
-
userIds,
|
|
466
|
-
_options$groupIds,
|
|
467
|
-
groupIds,
|
|
468
|
-
_options$write,
|
|
469
|
-
write,
|
|
470
|
-
_options$replace,
|
|
471
|
-
replace,
|
|
472
|
-
_options$save,
|
|
473
|
-
save,
|
|
474
|
-
iac,
|
|
475
|
-
grantType,
|
|
476
|
-
existingUsers,
|
|
477
|
-
mergedUsers,
|
|
478
|
-
existingGroups,
|
|
479
|
-
mergedGroups,
|
|
480
|
-
_args4 = arguments;
|
|
481
|
-
return _regenerator().w(function (_context4) {
|
|
482
|
-
while (1) switch (_context4.n) {
|
|
483
|
-
case 0:
|
|
484
|
-
options = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {};
|
|
485
|
-
_options$userIds = options.userIds, userIds = _options$userIds === void 0 ? [] : _options$userIds, _options$groupIds = options.groupIds, groupIds = _options$groupIds === void 0 ? [] : _options$groupIds, _options$write = options.write, write = _options$write === void 0 ? false : _options$write, _options$replace = options.replace, replace = _options$replace === void 0 ? false : _options$replace, _options$save = options.save, save = _options$save === void 0 ? true : _options$save; // Validate inputs
|
|
486
|
-
if (Array.isArray(userIds)) {
|
|
487
|
-
_context4.n = 1;
|
|
488
|
-
break;
|
|
489
|
-
}
|
|
490
|
-
throw new Error('userIds must be an array');
|
|
491
|
-
case 1:
|
|
492
|
-
if (Array.isArray(groupIds)) {
|
|
493
|
-
_context4.n = 2;
|
|
494
|
-
break;
|
|
495
|
-
}
|
|
496
|
-
throw new Error('groupIds must be an array');
|
|
497
|
-
case 2:
|
|
498
|
-
// Get current IAC settings
|
|
499
|
-
iac = this.get('iac') || {}; // Determine which grant type to update (read or write)
|
|
500
|
-
grantType = write ? 'writeGrants' : 'readGrants'; // Initialize grants if they don't exist
|
|
501
|
-
if (!iac[grantType]) {
|
|
502
|
-
iac[grantType] = {};
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
// Handle users
|
|
506
|
-
if (userIds.length > 0) {
|
|
507
|
-
if (replace) {
|
|
508
|
-
// Replace existing users
|
|
509
|
-
iac[grantType].users = _toConsumableArray(userIds);
|
|
510
|
-
} else {
|
|
511
|
-
// Merge with existing users (avoiding duplicates)
|
|
512
|
-
existingUsers = iac[grantType].users || [];
|
|
513
|
-
mergedUsers = _toConsumableArray(new Set([].concat(_toConsumableArray(existingUsers), _toConsumableArray(userIds))));
|
|
514
|
-
iac[grantType].users = mergedUsers;
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
// Handle user groups
|
|
519
|
-
if (groupIds.length > 0) {
|
|
520
|
-
if (replace) {
|
|
521
|
-
// Replace existing groups
|
|
522
|
-
iac[grantType].userGroups = _toConsumableArray(groupIds);
|
|
523
|
-
} else {
|
|
524
|
-
// Merge with existing groups (avoiding duplicates)
|
|
525
|
-
existingGroups = iac[grantType].userGroups || [];
|
|
526
|
-
mergedGroups = _toConsumableArray(new Set([].concat(_toConsumableArray(existingGroups), _toConsumableArray(groupIds))));
|
|
527
|
-
iac[grantType].userGroups = mergedGroups;
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
// Update the object
|
|
532
|
-
this.set('iac', iac);
|
|
533
|
-
|
|
534
|
-
// Save if requested
|
|
535
|
-
if (!save) {
|
|
536
|
-
_context4.n = 4;
|
|
537
|
-
break;
|
|
538
|
-
}
|
|
539
|
-
_context4.n = 3;
|
|
540
|
-
return this.save();
|
|
541
|
-
case 3:
|
|
542
|
-
return _context4.a(2, _context4.v);
|
|
543
|
-
case 4:
|
|
544
|
-
return _context4.a(2, this);
|
|
545
|
-
}
|
|
546
|
-
}, _callee4, this);
|
|
547
|
-
}));
|
|
548
|
-
function grantAccess() {
|
|
549
|
-
return _grantAccess.apply(this, arguments);
|
|
550
|
-
}
|
|
551
|
-
return grantAccess;
|
|
552
|
-
}()
|
|
553
|
-
/**
|
|
554
|
-
* Publishes this object to make it publicly accessible (or unpublishes it).
|
|
555
|
-
* Adds or removes 'public_user' from the IAC read permissions.
|
|
556
|
-
*
|
|
557
|
-
* @param {Object} options - Publishing options
|
|
558
|
-
* @param {boolean} [options.publish=true] - If true, publishes the object; if false, unpublishes it
|
|
559
|
-
* @param {boolean} [options.save=true] - If true, automatically saves the object after updating permissions
|
|
560
|
-
* @returns {Promise<RbtObject>} - Returns this object (saved if options.save is true)
|
|
561
|
-
*
|
|
562
|
-
* @example
|
|
563
|
-
* // Publish an object (make it public)
|
|
564
|
-
* await myObject.publishObject();
|
|
565
|
-
*
|
|
566
|
-
* @example
|
|
567
|
-
* // Unpublish an object (make it private)
|
|
568
|
-
* await myObject.publishObject({ publish: false });
|
|
569
|
-
*
|
|
570
|
-
* @example
|
|
571
|
-
* // Publish without auto-saving
|
|
572
|
-
* await myObject.publishObject({ save: false });
|
|
573
|
-
* // ... make other changes ...
|
|
574
|
-
* await myObject.save();
|
|
575
|
-
*/
|
|
576
|
-
)
|
|
577
|
-
}, {
|
|
578
|
-
key: "publishObject",
|
|
579
|
-
value: (function () {
|
|
580
|
-
var _publishObject = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
|
|
581
|
-
var options,
|
|
582
|
-
_options$publish,
|
|
583
|
-
publish,
|
|
584
|
-
_options$save2,
|
|
585
|
-
save,
|
|
586
|
-
currentIac,
|
|
587
|
-
iac,
|
|
588
|
-
_args5 = arguments;
|
|
589
|
-
return _regenerator().w(function (_context5) {
|
|
590
|
-
while (1) switch (_context5.n) {
|
|
591
|
-
case 0:
|
|
592
|
-
options = _args5.length > 0 && _args5[0] !== undefined ? _args5[0] : {};
|
|
593
|
-
_options$publish = options.publish, publish = _options$publish === void 0 ? true : _options$publish, _options$save2 = options.save, save = _options$save2 === void 0 ? true : _options$save2; // Get current IAC settings and create a deep clone to ensure change detection
|
|
594
|
-
currentIac = this.get('iac') || {};
|
|
595
|
-
iac = _.cloneDeep(currentIac); // Initialize readGrants if it doesn't exist
|
|
596
|
-
if (!iac.readGrants) {
|
|
597
|
-
iac.readGrants = {};
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
// Initialize users array if it doesn't exist
|
|
601
|
-
if (!Array.isArray(iac.readGrants.users)) {
|
|
602
|
-
iac.readGrants.users = [];
|
|
603
|
-
}
|
|
604
|
-
if (publish) {
|
|
605
|
-
// Add public_user if not already present
|
|
606
|
-
if (!iac.readGrants.users.includes('public_user')) {
|
|
607
|
-
iac.readGrants.users.push('public_user');
|
|
608
|
-
}
|
|
609
|
-
} else {
|
|
610
|
-
// Remove public_user
|
|
611
|
-
iac.readGrants.users = iac.readGrants.users.filter(function (userId) {
|
|
612
|
-
return userId !== 'public_user';
|
|
613
|
-
});
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
// Update the object with the cloned and modified IAC
|
|
617
|
-
this.set('iac', iac);
|
|
618
|
-
|
|
619
|
-
// Save if requested
|
|
620
|
-
if (!save) {
|
|
621
|
-
_context5.n = 2;
|
|
622
|
-
break;
|
|
623
|
-
}
|
|
624
|
-
_context5.n = 1;
|
|
625
|
-
return this.save();
|
|
626
|
-
case 1:
|
|
627
|
-
return _context5.a(2, _context5.v);
|
|
628
|
-
case 2:
|
|
629
|
-
return _context5.a(2, this);
|
|
630
|
-
}
|
|
631
|
-
}, _callee5, this);
|
|
632
|
-
}));
|
|
633
|
-
function publishObject() {
|
|
634
|
-
return _publishObject.apply(this, arguments);
|
|
635
|
-
}
|
|
636
|
-
return publishObject;
|
|
637
|
-
}()
|
|
638
|
-
/**
|
|
639
|
-
* Unpublishes this object to remove public access.
|
|
640
|
-
* Removes 'public_user' from the IAC read permissions.
|
|
641
|
-
* This is an alias for publishObject({ publish: false }) for better code clarity.
|
|
642
|
-
*
|
|
643
|
-
* @param {Object} options - Unpublishing options
|
|
644
|
-
* @param {boolean} [options.save=true] - If true, automatically saves the object after updating permissions
|
|
645
|
-
* @returns {Promise<RbtObject>} - Returns this object (saved if options.save is true)
|
|
646
|
-
*
|
|
647
|
-
* @example
|
|
648
|
-
* // Unpublish an object (remove public access)
|
|
649
|
-
* await myObject.unpublishObject();
|
|
650
|
-
*
|
|
651
|
-
* @example
|
|
652
|
-
* // Unpublish without auto-saving
|
|
653
|
-
* await myObject.unpublishObject({ save: false });
|
|
654
|
-
* // ... make other changes ...
|
|
655
|
-
* await myObject.save();
|
|
656
|
-
*/
|
|
657
|
-
)
|
|
658
|
-
}, {
|
|
659
|
-
key: "unpublishObject",
|
|
660
|
-
value: (function () {
|
|
661
|
-
var _unpublishObject = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6() {
|
|
662
|
-
var options,
|
|
663
|
-
_args6 = arguments;
|
|
664
|
-
return _regenerator().w(function (_context6) {
|
|
665
|
-
while (1) switch (_context6.n) {
|
|
666
|
-
case 0:
|
|
667
|
-
options = _args6.length > 0 && _args6[0] !== undefined ? _args6[0] : {};
|
|
668
|
-
_context6.n = 1;
|
|
669
|
-
return this.publishObject({
|
|
670
|
-
publish: false,
|
|
671
|
-
save: options.save !== undefined ? options.save : true
|
|
672
|
-
});
|
|
673
|
-
case 1:
|
|
674
|
-
return _context6.a(2, _context6.v);
|
|
675
|
-
}
|
|
676
|
-
}, _callee6, this);
|
|
677
|
-
}));
|
|
678
|
-
function unpublishObject() {
|
|
679
|
-
return _unpublishObject.apply(this, arguments);
|
|
680
|
-
}
|
|
681
|
-
return unpublishObject;
|
|
682
|
-
}()
|
|
683
|
-
/**
|
|
684
|
-
* Revokes access from specific users and/or user groups.
|
|
685
|
-
*
|
|
686
|
-
* @param {Object} options - Access revocation options
|
|
687
|
-
* @param {string[]} [options.userIds=[]] - Array of user IDs to remove from read or write access
|
|
688
|
-
* @param {string[]} [options.groupIds=[]] - Array of group IDs to remove from read or write access
|
|
689
|
-
* @param {boolean} [options.write=false] - If true, removes write access; if false, removes read access
|
|
690
|
-
* @param {boolean} [options.save=true] - If true, automatically saves the object after updating permissions
|
|
691
|
-
* @returns {Promise<RbtObject>} - Returns this object (saved if options.save is true)
|
|
692
|
-
*
|
|
693
|
-
* @example
|
|
694
|
-
* // Revoke read access from specific users
|
|
695
|
-
* await myObject.revokeAccess({
|
|
696
|
-
* userIds: ['user_123', 'user_456']
|
|
697
|
-
* });
|
|
698
|
-
*
|
|
699
|
-
* @example
|
|
700
|
-
* // Revoke write access from specific groups
|
|
701
|
-
* await myObject.revokeAccess({
|
|
702
|
-
* groupIds: ['grpEditors'],
|
|
703
|
-
* write: true
|
|
704
|
-
* });
|
|
705
|
-
*
|
|
706
|
-
* @example
|
|
707
|
-
* // Revoke access from users and groups
|
|
708
|
-
* await myObject.revokeAccess({
|
|
709
|
-
* userIds: ['user_123'],
|
|
710
|
-
* groupIds: ['grpViewers']
|
|
711
|
-
* });
|
|
712
|
-
*
|
|
713
|
-
* @example
|
|
714
|
-
* // Revoke without auto-saving
|
|
715
|
-
* await myObject.revokeAccess({
|
|
716
|
-
* userIds: ['user_123'],
|
|
717
|
-
* save: false
|
|
718
|
-
* });
|
|
719
|
-
*/
|
|
720
|
-
)
|
|
721
|
-
}, {
|
|
722
|
-
key: "revokeAccess",
|
|
723
|
-
value: (function () {
|
|
724
|
-
var _revokeAccess = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
|
|
725
|
-
var options,
|
|
726
|
-
_options$userIds2,
|
|
727
|
-
userIds,
|
|
728
|
-
_options$groupIds2,
|
|
729
|
-
groupIds,
|
|
730
|
-
_options$write2,
|
|
731
|
-
write,
|
|
732
|
-
_options$save3,
|
|
733
|
-
save,
|
|
734
|
-
iac,
|
|
735
|
-
grantType,
|
|
736
|
-
_args7 = arguments;
|
|
737
|
-
return _regenerator().w(function (_context7) {
|
|
738
|
-
while (1) switch (_context7.n) {
|
|
739
|
-
case 0:
|
|
740
|
-
options = _args7.length > 0 && _args7[0] !== undefined ? _args7[0] : {};
|
|
741
|
-
_options$userIds2 = options.userIds, userIds = _options$userIds2 === void 0 ? [] : _options$userIds2, _options$groupIds2 = options.groupIds, groupIds = _options$groupIds2 === void 0 ? [] : _options$groupIds2, _options$write2 = options.write, write = _options$write2 === void 0 ? false : _options$write2, _options$save3 = options.save, save = _options$save3 === void 0 ? true : _options$save3; // Validate inputs
|
|
742
|
-
if (Array.isArray(userIds)) {
|
|
743
|
-
_context7.n = 1;
|
|
744
|
-
break;
|
|
745
|
-
}
|
|
746
|
-
throw new Error('userIds must be an array');
|
|
747
|
-
case 1:
|
|
748
|
-
if (Array.isArray(groupIds)) {
|
|
749
|
-
_context7.n = 2;
|
|
750
|
-
break;
|
|
751
|
-
}
|
|
752
|
-
throw new Error('groupIds must be an array');
|
|
753
|
-
case 2:
|
|
754
|
-
// Get current IAC settings
|
|
755
|
-
iac = this.get('iac') || {}; // Determine which grant type to update (read or write)
|
|
756
|
-
grantType = write ? 'writeGrants' : 'readGrants'; // Initialize grants if they don't exist
|
|
757
|
-
if (!iac[grantType]) {
|
|
758
|
-
iac[grantType] = {};
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
// Remove specified users
|
|
762
|
-
if (userIds.length > 0 && Array.isArray(iac[grantType].users)) {
|
|
763
|
-
iac[grantType].users = iac[grantType].users.filter(function (userId) {
|
|
764
|
-
return !userIds.includes(userId);
|
|
765
|
-
});
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
// Remove specified groups
|
|
769
|
-
if (groupIds.length > 0 && Array.isArray(iac[grantType].userGroups)) {
|
|
770
|
-
iac[grantType].userGroups = iac[grantType].userGroups.filter(function (groupId) {
|
|
771
|
-
return !groupIds.includes(groupId);
|
|
772
|
-
});
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
// Update the object
|
|
776
|
-
this.set('iac', iac);
|
|
777
|
-
|
|
778
|
-
// Save if requested
|
|
779
|
-
if (!save) {
|
|
780
|
-
_context7.n = 4;
|
|
781
|
-
break;
|
|
782
|
-
}
|
|
783
|
-
_context7.n = 3;
|
|
784
|
-
return this.save();
|
|
785
|
-
case 3:
|
|
786
|
-
return _context7.a(2, _context7.v);
|
|
787
|
-
case 4:
|
|
788
|
-
return _context7.a(2, this);
|
|
789
|
-
}
|
|
790
|
-
}, _callee7, this);
|
|
791
|
-
}));
|
|
792
|
-
function revokeAccess() {
|
|
793
|
-
return _revokeAccess.apply(this, arguments);
|
|
794
|
-
}
|
|
795
|
-
return revokeAccess;
|
|
796
|
-
}()
|
|
797
|
-
/**
|
|
798
|
-
* Checks if this object is currently published (publicly accessible).
|
|
799
|
-
*
|
|
800
|
-
* @returns {boolean} - True if 'public_user' is in the read grants, false otherwise
|
|
801
|
-
*
|
|
802
|
-
* @example
|
|
803
|
-
* if (myObject.isPublished()) {
|
|
804
|
-
* console.log('Object is public');
|
|
805
|
-
* }
|
|
806
|
-
*/
|
|
807
|
-
)
|
|
808
|
-
}, {
|
|
809
|
-
key: "isPublished",
|
|
810
|
-
value: function isPublished() {
|
|
811
|
-
var iac = this.get('iac');
|
|
812
|
-
if (!iac || !iac.readGrants || !Array.isArray(iac.readGrants.users)) {
|
|
813
|
-
return false;
|
|
814
|
-
}
|
|
815
|
-
return iac.readGrants.users.includes('public_user');
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
/**
|
|
819
|
-
* Gets the current sharing permissions for this object.
|
|
820
|
-
*
|
|
821
|
-
* @returns {Object} - Object containing read and write grants
|
|
822
|
-
* @returns {Object} returns.readGrants - Read access grants
|
|
823
|
-
* @returns {string[]} returns.readGrants.users - Array of user IDs with read access
|
|
824
|
-
* @returns {string[]} returns.readGrants.userGroups - Array of group IDs with read access
|
|
825
|
-
* @returns {string[]} returns.readGrants.organizations - Array of organization IDs with read access
|
|
826
|
-
* @returns {Object} returns.writeGrants - Write access grants
|
|
827
|
-
* @returns {string[]} returns.writeGrants.users - Array of user IDs with write access
|
|
828
|
-
* @returns {string[]} returns.writeGrants.userGroups - Array of group IDs with write access
|
|
829
|
-
* @returns {string[]} returns.writeGrants.organizations - Array of organization IDs with write access
|
|
830
|
-
*
|
|
831
|
-
* @example
|
|
832
|
-
* const permissions = myObject.getSharing();
|
|
833
|
-
* console.log('Read users:', permissions.readGrants.users);
|
|
834
|
-
* console.log('Read groups:', permissions.readGrants.userGroups);
|
|
835
|
-
*/
|
|
836
|
-
}, {
|
|
837
|
-
key: "getSharing",
|
|
838
|
-
value: function getSharing() {
|
|
839
|
-
var _iac$readGrants, _iac$readGrants2, _iac$readGrants3, _iac$readGrants4, _iac$writeGrants, _iac$writeGrants2, _iac$writeGrants3, _iac$writeGrants4;
|
|
840
|
-
var iac = this.get('iac') || {};
|
|
841
|
-
return {
|
|
842
|
-
readGrants: {
|
|
843
|
-
users: ((_iac$readGrants = iac.readGrants) === null || _iac$readGrants === void 0 ? void 0 : _iac$readGrants.users) || [],
|
|
844
|
-
userGroups: ((_iac$readGrants2 = iac.readGrants) === null || _iac$readGrants2 === void 0 ? void 0 : _iac$readGrants2.userGroups) || [],
|
|
845
|
-
organizations: ((_iac$readGrants3 = iac.readGrants) === null || _iac$readGrants3 === void 0 ? void 0 : _iac$readGrants3.organizations) || [],
|
|
846
|
-
userSegments: ((_iac$readGrants4 = iac.readGrants) === null || _iac$readGrants4 === void 0 ? void 0 : _iac$readGrants4.userSegments) || []
|
|
847
|
-
},
|
|
848
|
-
writeGrants: {
|
|
849
|
-
users: ((_iac$writeGrants = iac.writeGrants) === null || _iac$writeGrants === void 0 ? void 0 : _iac$writeGrants.users) || [],
|
|
850
|
-
userGroups: ((_iac$writeGrants2 = iac.writeGrants) === null || _iac$writeGrants2 === void 0 ? void 0 : _iac$writeGrants2.userGroups) || [],
|
|
851
|
-
organizations: ((_iac$writeGrants3 = iac.writeGrants) === null || _iac$writeGrants3 === void 0 ? void 0 : _iac$writeGrants3.organizations) || [],
|
|
852
|
-
userSegments: ((_iac$writeGrants4 = iac.writeGrants) === null || _iac$writeGrants4 === void 0 ? void 0 : _iac$writeGrants4.userSegments) || []
|
|
853
|
-
}
|
|
854
|
-
};
|
|
855
|
-
}
|
|
856
|
-
}, {
|
|
857
|
-
key: "delete",
|
|
858
|
-
value: function () {
|
|
859
|
-
var _delete2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8() {
|
|
860
|
-
var record, response, _t2;
|
|
861
|
-
return _regenerator().w(function (_context8) {
|
|
862
|
-
while (1) switch (_context8.p = _context8.n) {
|
|
863
|
-
case 0:
|
|
864
|
-
if (this._internalData.type) {
|
|
865
|
-
_context8.n = 1;
|
|
866
|
-
break;
|
|
867
|
-
}
|
|
868
|
-
throw new Error('Cannot delete object without type');
|
|
869
|
-
case 1:
|
|
870
|
-
_context8.p = 1;
|
|
871
|
-
record = this.toRecord();
|
|
872
|
-
_context8.n = 2;
|
|
873
|
-
return this._axios.post('/object_service/deleteObject', {
|
|
874
|
-
id: record.id,
|
|
875
|
-
type: record.type
|
|
876
|
-
});
|
|
877
|
-
case 2:
|
|
878
|
-
response = _context8.v;
|
|
879
|
-
if (!(response.data.ok === false)) {
|
|
880
|
-
_context8.n = 3;
|
|
881
|
-
break;
|
|
882
|
-
}
|
|
883
|
-
throw new Error(response.data.message);
|
|
884
|
-
case 3:
|
|
885
|
-
this._internalData = response.data;
|
|
886
|
-
return _context8.a(2, this);
|
|
887
|
-
case 4:
|
|
888
|
-
_context8.p = 4;
|
|
889
|
-
_t2 = _context8.v;
|
|
890
|
-
console.log('RbtObject.delete.error:');
|
|
891
|
-
console.log(_t2.response.data);
|
|
892
|
-
throw _t2;
|
|
893
|
-
case 5:
|
|
894
|
-
return _context8.a(2);
|
|
895
|
-
}
|
|
896
|
-
}, _callee8, this, [[1, 4]]);
|
|
897
|
-
}));
|
|
898
|
-
function _delete() {
|
|
899
|
-
return _delete2.apply(this, arguments);
|
|
900
|
-
}
|
|
901
|
-
return _delete;
|
|
902
|
-
}()
|
|
903
|
-
}, {
|
|
904
|
-
key: "_deepUnpackJson",
|
|
905
|
-
value: function _deepUnpackJson(value) {
|
|
906
|
-
if (typeof value === 'string') {
|
|
907
|
-
try {
|
|
908
|
-
// Only parse as JSON if it's not a large number
|
|
909
|
-
// https://chatgpt.com/c/6745902c-edf4-800c-ab52-31bf27dde2bd
|
|
910
|
-
//
|
|
911
|
-
if (!/^\d{16,}$/.test(value)) {
|
|
912
|
-
var parsed = JSON.parse(value);
|
|
913
|
-
// Recursively parse if the result is a string, object, or array
|
|
914
|
-
return this._deepUnpackJson(parsed);
|
|
915
|
-
}
|
|
916
|
-
} catch (e) {
|
|
917
|
-
return value; // Return the original string if parsing fails
|
|
918
|
-
}
|
|
919
|
-
} else if (value !== null && _typeof(value) === 'object') {
|
|
920
|
-
// If it's an object (including arrays), recursively parse each value
|
|
921
|
-
for (var key in value) {
|
|
922
|
-
value[key] = this._deepUnpackJson(value[key]);
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
return value;
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
//
|
|
929
|
-
// Realtime WebSocket
|
|
930
|
-
//
|
|
931
|
-
//
|
|
932
|
-
}, {
|
|
933
|
-
key: "_initRealtime",
|
|
934
|
-
value: function _initRealtime() {
|
|
935
|
-
if (this._realtime || !this._axios) return;
|
|
936
|
-
|
|
937
|
-
// Use stored websocket client if available
|
|
938
|
-
var ws = this._ws;
|
|
939
|
-
|
|
940
|
-
// Otherwise, lazily pull WebSocket from parent API (injected via axios instance)
|
|
941
|
-
if (!ws) {
|
|
942
|
-
var _this$_axios;
|
|
943
|
-
var api = (_this$_axios = this._axios) === null || _this$_axios === void 0 ? void 0 : _this$_axios.__rbtApiInstance;
|
|
944
|
-
if (!api || typeof api.getWebSocketClient !== 'function') return;
|
|
945
|
-
ws = api.getWebSocketClient();
|
|
946
|
-
}
|
|
947
|
-
if (!ws || this._realtime) return;
|
|
948
|
-
this._ws = ws;
|
|
949
|
-
this._realtime = true;
|
|
950
|
-
this._subscribeToRealtime(ws);
|
|
951
|
-
}
|
|
952
|
-
}, {
|
|
953
|
-
key: "_subscribeToRealtime",
|
|
954
|
-
value: function _subscribeToRealtime(ws) {
|
|
955
|
-
var _this$_axios2,
|
|
956
|
-
_this3 = this;
|
|
957
|
-
// Track subscription for reconnection
|
|
958
|
-
var api = (_this$_axios2 = this._axios) === null || _this$_axios2 === void 0 ? void 0 : _this$_axios2.__rbtApiInstance;
|
|
959
|
-
if (api && typeof api._trackSubscription === 'function') {
|
|
960
|
-
api._trackSubscription(this.id);
|
|
961
|
-
}
|
|
962
|
-
if (ws.readyState === 1) {
|
|
963
|
-
ws.send(JSON.stringify({
|
|
964
|
-
type: 'subscribe',
|
|
965
|
-
objectId: this.id
|
|
966
|
-
}));
|
|
967
|
-
} else {
|
|
968
|
-
ws.addEventListener('open', function () {
|
|
969
|
-
ws.send(JSON.stringify({
|
|
970
|
-
type: 'subscribe',
|
|
971
|
-
objectId: _this3.id
|
|
972
|
-
}));
|
|
973
|
-
});
|
|
974
|
-
}
|
|
975
|
-
ws.addEventListener('message', function (event) {
|
|
976
|
-
try {
|
|
977
|
-
var msg = JSON.parse(event.data);
|
|
978
|
-
if (msg.objectId !== _this3.id) return;
|
|
979
|
-
if (msg.type === 'update') {
|
|
980
|
-
if (msg.delta && msg.delta.path !== undefined) {
|
|
981
|
-
_.set(_this3._data, msg.delta.path, msg.delta.value);
|
|
982
|
-
|
|
983
|
-
// Add metadata to indicate if this is state sync vs live update
|
|
984
|
-
var changeData = _objectSpread(_objectSpread({}, msg.delta), {}, {
|
|
985
|
-
isStateSync: msg.isStateSync || false,
|
|
986
|
-
source: msg.isStateSync ? 'state-sync' : 'realtime',
|
|
987
|
-
userId: msg.userId || msg.delta.userId || null
|
|
988
|
-
});
|
|
989
|
-
_this3._trigger('change', changeData);
|
|
990
|
-
if (msg.isStateSync) {
|
|
991
|
-
console.log('[RbtObject] Applied state sync:', msg.delta.path, '=', msg.delta.value);
|
|
992
|
-
}
|
|
993
|
-
} else {
|
|
994
|
-
console.warn('[RbtObject] Received update message without valid delta:', msg);
|
|
995
|
-
}
|
|
996
|
-
} else if (msg.type === 'save') {
|
|
997
|
-
_this3._trigger('save', msg.revision || {});
|
|
998
|
-
}
|
|
999
|
-
} catch (error) {
|
|
1000
|
-
console.error('[RbtObject] Error processing WebSocket message:', error, event.data);
|
|
1001
|
-
}
|
|
1002
|
-
});
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
// General change handler for both local and remote changes
|
|
1006
|
-
}, {
|
|
1007
|
-
key: "onChange",
|
|
1008
|
-
value: function onChange(cb) {
|
|
1009
|
-
this._eventHandlers.change.push(cb);
|
|
1010
|
-
// Auto-initialize realtime if this object has WebSocket capability
|
|
1011
|
-
if (this._ws && !this._realtime) {
|
|
1012
|
-
this._initRealtime();
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
// General save handler for both local and remote saves
|
|
1017
|
-
}, {
|
|
1018
|
-
key: "onSave",
|
|
1019
|
-
value: function onSave(cb) {
|
|
1020
|
-
this._eventHandlers.save.push(cb);
|
|
1021
|
-
// Note: Does not initialize realtime connection
|
|
1022
|
-
}
|
|
1023
|
-
}, {
|
|
1024
|
-
key: "_trigger",
|
|
1025
|
-
value: function _trigger(type, data) {
|
|
1026
|
-
var _this$_eventHandlers$;
|
|
1027
|
-
console.log('[AgentProviderSync] _trigger called:', type, 'handlers:', (_this$_eventHandlers$ = this._eventHandlers[type]) === null || _this$_eventHandlers$ === void 0 ? void 0 : _this$_eventHandlers$.length, 'data:', data);
|
|
1028
|
-
var _iterator = _createForOfIteratorHelper(this._eventHandlers[type] || []),
|
|
1029
|
-
_step;
|
|
1030
|
-
try {
|
|
1031
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
1032
|
-
var fn = _step.value;
|
|
1033
|
-
fn(data);
|
|
1034
|
-
}
|
|
1035
|
-
} catch (err) {
|
|
1036
|
-
_iterator.e(err);
|
|
1037
|
-
} finally {
|
|
1038
|
-
_iterator.f();
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
}, {
|
|
1042
|
-
key: "_broadcastChange",
|
|
1043
|
-
value: function _broadcastChange(path, value) {
|
|
1044
|
-
var _this4 = this;
|
|
1045
|
-
if (!this._realtime || !this._ws || this._ws.readyState !== 1) {
|
|
1046
|
-
return;
|
|
1047
|
-
}
|
|
1048
|
-
|
|
1049
|
-
// Store the pending broadcast
|
|
1050
|
-
this._pendingBroadcasts.set(path, value);
|
|
1051
|
-
|
|
1052
|
-
// Clear existing timer if any
|
|
1053
|
-
if (this._broadcastDebounceTimer) {
|
|
1054
|
-
clearTimeout(this._broadcastDebounceTimer);
|
|
1055
|
-
}
|
|
1056
|
-
|
|
1057
|
-
// Set new debounced timer
|
|
1058
|
-
this._broadcastDebounceTimer = setTimeout(function () {
|
|
1059
|
-
_this4._flushPendingBroadcasts();
|
|
1060
|
-
}, 300);
|
|
1061
|
-
}
|
|
1062
|
-
}, {
|
|
1063
|
-
key: "_flushPendingBroadcasts",
|
|
1064
|
-
value: function _flushPendingBroadcasts() {
|
|
1065
|
-
if (!this._realtime || !this._ws || this._ws.readyState !== 1) {
|
|
1066
|
-
this._pendingBroadcasts.clear();
|
|
1067
|
-
return;
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1070
|
-
// Send all pending broadcasts
|
|
1071
|
-
var _iterator2 = _createForOfIteratorHelper(this._pendingBroadcasts),
|
|
1072
|
-
_step2;
|
|
1073
|
-
try {
|
|
1074
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
1075
|
-
var _step2$value = _slicedToArray(_step2.value, 2),
|
|
1076
|
-
path = _step2$value[0],
|
|
1077
|
-
value = _step2$value[1];
|
|
1078
|
-
this._ws.send(JSON.stringify({
|
|
1079
|
-
type: 'update',
|
|
1080
|
-
objectId: this.id,
|
|
1081
|
-
delta: {
|
|
1082
|
-
path: path,
|
|
1083
|
-
value: value
|
|
1084
|
-
}
|
|
1085
|
-
}));
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
// Clear pending broadcasts and timer
|
|
1089
|
-
} catch (err) {
|
|
1090
|
-
_iterator2.e(err);
|
|
1091
|
-
} finally {
|
|
1092
|
-
_iterator2.f();
|
|
1093
|
-
}
|
|
1094
|
-
this._pendingBroadcasts.clear();
|
|
1095
|
-
this._broadcastDebounceTimer = null;
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
// Cleanup method to clear any pending debounced broadcasts
|
|
1099
|
-
}, {
|
|
1100
|
-
key: "_cleanup",
|
|
1101
|
-
value: function _cleanup() {
|
|
1102
|
-
if (this._broadcastDebounceTimer) {
|
|
1103
|
-
clearTimeout(this._broadcastDebounceTimer);
|
|
1104
|
-
this._broadcastDebounceTimer = null;
|
|
1105
|
-
}
|
|
1106
|
-
this._pendingBroadcasts.clear();
|
|
1107
|
-
}
|
|
1108
|
-
}]);
|
|
1109
|
-
}();
|
|
1110
|
-
export { RbtObject as default };
|