roboto-js 1.7.1 → 1.7.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 -0
- package/dist/cjs/cookie_storage_adaptor.cjs +429 -0
- package/dist/cjs/index.cjs +57 -5
- package/dist/cjs/rbt_api.cjs +548 -463
- package/dist/cookie_storage_adaptor.js +415 -0
- package/dist/esm/cookie_storage_adaptor.js +226 -0
- package/dist/esm/index.js +37 -5
- package/dist/esm/rbt_api.js +50 -22
- package/dist/index.js +66 -40
- package/dist/rbt_api.js +574 -496
- package/dist/rbt_file.js +10 -16
- package/dist/rbt_metrics_api.js +6 -12
- package/dist/rbt_object.js +30 -36
- package/dist/rbt_user.js +11 -17
- package/package.json +1 -1
- package/src/cookie_storage_adaptor.js +246 -0
- package/src/index.js +41 -5
- package/src/rbt_api.js +51 -20
package/dist/rbt_file.js
CHANGED
|
@@ -1,14 +1,4 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
1
|
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); }
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports["default"] = void 0;
|
|
8
|
-
var _tusJsClient = require("tus-js-client");
|
|
9
|
-
var _lodash = _interopRequireDefault(require("lodash"));
|
|
10
|
-
var _eventemitter = _interopRequireDefault(require("eventemitter3"));
|
|
11
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
12
2
|
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 }; })(); }
|
|
13
3
|
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); }
|
|
14
4
|
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); }
|
|
@@ -28,7 +18,10 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
|
|
|
28
18
|
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
29
19
|
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
30
20
|
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
31
|
-
|
|
21
|
+
import { Upload } from 'tus-js-client';
|
|
22
|
+
import _ from 'lodash';
|
|
23
|
+
import EventEmitter from 'eventemitter3';
|
|
24
|
+
var RbtFile = /*#__PURE__*/function (_EventEmitter) {
|
|
32
25
|
function RbtFile(record, axiosInstance) {
|
|
33
26
|
var _this;
|
|
34
27
|
_classCallCheck(this, RbtFile);
|
|
@@ -46,12 +39,12 @@ var RbtFile = exports["default"] = /*#__PURE__*/function (_EventEmitter) {
|
|
|
46
39
|
return _createClass(RbtFile, [{
|
|
47
40
|
key: "get",
|
|
48
41
|
value: function get(path) {
|
|
49
|
-
return
|
|
42
|
+
return _.get(this._data, path);
|
|
50
43
|
}
|
|
51
44
|
}, {
|
|
52
45
|
key: "set",
|
|
53
46
|
value: function set(path, value) {
|
|
54
|
-
|
|
47
|
+
_.set(this._data, path, value);
|
|
55
48
|
}
|
|
56
49
|
}, {
|
|
57
50
|
key: "getData",
|
|
@@ -62,7 +55,7 @@ var RbtFile = exports["default"] = /*#__PURE__*/function (_EventEmitter) {
|
|
|
62
55
|
key: "setData",
|
|
63
56
|
value: function setData(data) {
|
|
64
57
|
// Use lodash's merge to deeply merge the incoming data into _data
|
|
65
|
-
|
|
58
|
+
_.merge(this._data, data);
|
|
66
59
|
return _objectSpread({}, this._data); // Return the updated _data as a new object
|
|
67
60
|
}
|
|
68
61
|
}, {
|
|
@@ -163,7 +156,7 @@ var RbtFile = exports["default"] = /*#__PURE__*/function (_EventEmitter) {
|
|
|
163
156
|
value: function uploadFile(file) {
|
|
164
157
|
var _this2 = this;
|
|
165
158
|
return new Promise(function (resolve, reject) {
|
|
166
|
-
var upload = new
|
|
159
|
+
var upload = new Upload(file, {
|
|
167
160
|
endpoint: _this2._axios.defaults.baseURL + "/file_service/files",
|
|
168
161
|
retryDelays: [0, 1000, 3000, 5000],
|
|
169
162
|
metadata: {
|
|
@@ -226,4 +219,5 @@ var RbtFile = exports["default"] = /*#__PURE__*/function (_EventEmitter) {
|
|
|
226
219
|
this.emit('progress', this.progress); // Emit a progress event
|
|
227
220
|
}
|
|
228
221
|
}]);
|
|
229
|
-
}(
|
|
222
|
+
}(EventEmitter);
|
|
223
|
+
export { RbtFile as default };
|
package/dist/rbt_metrics_api.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
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 _eventemitter = _interopRequireDefault(require("eventemitter3"));
|
|
9
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
10
1
|
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 }; })(); }
|
|
11
2
|
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); }
|
|
12
3
|
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); }
|
|
@@ -27,6 +18,8 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
|
|
|
27
18
|
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
28
19
|
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
29
20
|
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
21
|
+
import axios from 'axios';
|
|
22
|
+
import EventEmitter from 'eventemitter3';
|
|
30
23
|
function getOrCreateDeviceId() {
|
|
31
24
|
if (typeof window !== "undefined" && window.localStorage) {
|
|
32
25
|
var deviceId = localStorage.getItem('robotoDeviceId');
|
|
@@ -40,7 +33,7 @@ function getOrCreateDeviceId() {
|
|
|
40
33
|
// On server/Node.js, return undefined (or you can fallback to some other logic)
|
|
41
34
|
return undefined;
|
|
42
35
|
}
|
|
43
|
-
var RbtMetricsApi =
|
|
36
|
+
var RbtMetricsApi = /*#__PURE__*/function (_EventEmitter) {
|
|
44
37
|
/**
|
|
45
38
|
* You can pass either:
|
|
46
39
|
* - axiosInstance: an existing axios instance (recommended for same-host)
|
|
@@ -56,7 +49,7 @@ var RbtMetricsApi = exports["default"] = /*#__PURE__*/function (_EventEmitter) {
|
|
|
56
49
|
if (axiosInstance) {
|
|
57
50
|
_this._axios = axiosInstance;
|
|
58
51
|
} else if (config) {
|
|
59
|
-
_this._axios =
|
|
52
|
+
_this._axios = axios.create(config);
|
|
60
53
|
} else {
|
|
61
54
|
throw new Error("RbtMetricsApi requires either axiosInstance or config");
|
|
62
55
|
}
|
|
@@ -203,4 +196,5 @@ var RbtMetricsApi = exports["default"] = /*#__PURE__*/function (_EventEmitter) {
|
|
|
203
196
|
return countEvents;
|
|
204
197
|
}())
|
|
205
198
|
}]);
|
|
206
|
-
}(
|
|
199
|
+
}(EventEmitter);
|
|
200
|
+
export { RbtMetricsApi as default };
|
package/dist/rbt_object.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _lodash = _interopRequireDefault(require("lodash"));
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
9
1
|
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
10
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."); }
|
|
11
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; } }
|
|
@@ -30,7 +22,8 @@ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o =
|
|
|
30
22
|
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
31
23
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
32
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); }
|
|
33
|
-
|
|
25
|
+
import _ from 'lodash';
|
|
26
|
+
var RbtObject = /*#__PURE__*/function () {
|
|
34
27
|
function RbtObject(record, axiosInstance) {
|
|
35
28
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
36
29
|
_classCallCheck(this, RbtObject);
|
|
@@ -73,7 +66,7 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
73
66
|
return _createClass(RbtObject, [{
|
|
74
67
|
key: "get",
|
|
75
68
|
value: function get(path) {
|
|
76
|
-
return
|
|
69
|
+
return _.get(this._data, path);
|
|
77
70
|
}
|
|
78
71
|
}, {
|
|
79
72
|
key: "getData",
|
|
@@ -85,11 +78,11 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
85
78
|
// Return an object with only the specified keys
|
|
86
79
|
return keys.reduce(function (result, key) {
|
|
87
80
|
// Use lodash.get to handle deep key paths
|
|
88
|
-
var value =
|
|
81
|
+
var value = _.get(_this._data, key);
|
|
89
82
|
// If the value exists, add it to the result object using the key path as the property name
|
|
90
83
|
if (value !== undefined) {
|
|
91
84
|
// Create nested structure based on the key path
|
|
92
|
-
|
|
85
|
+
_.set(result, key, value);
|
|
93
86
|
}
|
|
94
87
|
return result;
|
|
95
88
|
}, {});
|
|
@@ -110,14 +103,14 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
110
103
|
key: "set",
|
|
111
104
|
value: function set(path, value) {
|
|
112
105
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
113
|
-
var currentValue =
|
|
106
|
+
var currentValue = _.get(this._data, path); // Fetch current value at deep path
|
|
114
107
|
|
|
115
108
|
if (options.merge) {
|
|
116
|
-
var mergedValue =
|
|
109
|
+
var mergedValue = _.mergeWith({}, currentValue, value, function (objValue, srcValue) {
|
|
117
110
|
if (srcValue === undefined) {
|
|
118
111
|
return undefined; // Indicate to delete when merging
|
|
119
112
|
}
|
|
120
|
-
if (
|
|
113
|
+
if (_.isArray(objValue)) {
|
|
121
114
|
return srcValue; // Customize merging behavior for arrays
|
|
122
115
|
}
|
|
123
116
|
// Handle null, 0, and "" explicitly
|
|
@@ -128,11 +121,11 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
128
121
|
// Process merged object to remove any keys set explicitly to undefined
|
|
129
122
|
Object.keys(mergedValue).forEach(function (key) {
|
|
130
123
|
if (mergedValue[key] === undefined) {
|
|
131
|
-
|
|
124
|
+
_.unset(mergedValue, key);
|
|
132
125
|
}
|
|
133
126
|
});
|
|
134
|
-
if (!
|
|
135
|
-
|
|
127
|
+
if (!_.isEqual(currentValue, mergedValue)) {
|
|
128
|
+
_.set(this._data, path, mergedValue); // Set the merged value at the deep path
|
|
136
129
|
this._addChange(path);
|
|
137
130
|
// Trigger local change events for any registered handlers
|
|
138
131
|
this._trigger('change', {
|
|
@@ -144,7 +137,7 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
144
137
|
} else {
|
|
145
138
|
// If value is undefined and not merging, delete the key
|
|
146
139
|
if (value === undefined) {
|
|
147
|
-
|
|
140
|
+
_.unset(this._data, path);
|
|
148
141
|
this._addChange(path);
|
|
149
142
|
// Trigger local change events for any registered handlers
|
|
150
143
|
this._trigger('change', {
|
|
@@ -152,8 +145,8 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
152
145
|
value: undefined,
|
|
153
146
|
options: options
|
|
154
147
|
});
|
|
155
|
-
} else if (!
|
|
156
|
-
|
|
148
|
+
} else if (!_.isEqual(currentValue, value)) {
|
|
149
|
+
_.set(this._data, path, value); // Set the value directly at the deep path
|
|
157
150
|
this._addChange(path);
|
|
158
151
|
this._broadcastChange(path, value);
|
|
159
152
|
// Trigger local change events for any registered handlers
|
|
@@ -176,11 +169,11 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
176
169
|
var _options$merge = options.merge,
|
|
177
170
|
merge = _options$merge === void 0 ? false : _options$merge;
|
|
178
171
|
Object.keys(newData).forEach(function (path) {
|
|
179
|
-
var currentValue =
|
|
172
|
+
var currentValue = _.get(_this2._data, path);
|
|
180
173
|
var newValue = newData[path];
|
|
181
|
-
if (merge &&
|
|
182
|
-
var mergedValue =
|
|
183
|
-
if (
|
|
174
|
+
if (merge && _.isObject(currentValue) && _.isObject(newValue)) {
|
|
175
|
+
var mergedValue = _.mergeWith({}, currentValue, newValue, function (objValue, srcValue) {
|
|
176
|
+
if (_.isArray(srcValue)) {
|
|
184
177
|
return _toConsumableArray(srcValue); // Customize merging behavior for arrays
|
|
185
178
|
}
|
|
186
179
|
// Handle null, 0, and "" explicitly
|
|
@@ -188,8 +181,8 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
188
181
|
return srcValue;
|
|
189
182
|
}
|
|
190
183
|
});
|
|
191
|
-
if (!
|
|
192
|
-
|
|
184
|
+
if (!_.isEqual(currentValue, mergedValue)) {
|
|
185
|
+
_.set(_this2._data, path, mergedValue);
|
|
193
186
|
_this2._addChange(path);
|
|
194
187
|
// Trigger change event for this path
|
|
195
188
|
_this2._trigger('change', {
|
|
@@ -198,9 +191,9 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
198
191
|
options: options
|
|
199
192
|
});
|
|
200
193
|
}
|
|
201
|
-
} else if (!
|
|
202
|
-
|
|
203
|
-
if (key === nsPath.split('.').pop() && !
|
|
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)) {
|
|
204
197
|
return nsObject[key] = {}; // Create any missing parts of the path as plain objects
|
|
205
198
|
}
|
|
206
199
|
return nsValue;
|
|
@@ -317,14 +310,14 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
317
310
|
// Populate deltaData only with keys specified in changes
|
|
318
311
|
changes.forEach(function (path) {
|
|
319
312
|
// default value explicitly set to undefined
|
|
320
|
-
var value =
|
|
313
|
+
var value = _.get(sourceData, path, undefined);
|
|
321
314
|
// Use _.set to ensure nested keys are correctly assigned
|
|
322
|
-
|
|
315
|
+
_.set(deltaData, path, value);
|
|
323
316
|
});
|
|
324
317
|
|
|
325
318
|
// mark as delta
|
|
326
319
|
this.rpcMeta.delta = true;
|
|
327
|
-
var clonedData =
|
|
320
|
+
var clonedData = _.cloneDeep(this._internalData);
|
|
328
321
|
clonedData.data = deltaData;
|
|
329
322
|
return _objectSpread(_objectSpread({}, clonedData), {}, {
|
|
330
323
|
dataJson: JSON.stringify(deltaData),
|
|
@@ -335,7 +328,7 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
335
328
|
key: "clone",
|
|
336
329
|
value: function clone() {
|
|
337
330
|
// Create a deep copy of the current object's data
|
|
338
|
-
var clonedData =
|
|
331
|
+
var clonedData = _.cloneDeep(this._internalData);
|
|
339
332
|
|
|
340
333
|
// Reset unique identifiers to ensure a new ID is generated upon saving
|
|
341
334
|
delete clonedData.id;
|
|
@@ -540,7 +533,7 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
540
533
|
if (msg.objectId !== _this3.id) return;
|
|
541
534
|
if (msg.type === 'update') {
|
|
542
535
|
if (msg.delta && msg.delta.path !== undefined) {
|
|
543
|
-
|
|
536
|
+
_.set(_this3._data, msg.delta.path, msg.delta.value);
|
|
544
537
|
|
|
545
538
|
// Add metadata to indicate if this is state sync vs live update
|
|
546
539
|
var changeData = _objectSpread(_objectSpread({}, msg.delta), {}, {
|
|
@@ -668,4 +661,5 @@ var RbtObject = exports["default"] = /*#__PURE__*/function () {
|
|
|
668
661
|
this._pendingBroadcasts.clear();
|
|
669
662
|
}
|
|
670
663
|
}]);
|
|
671
|
-
}();
|
|
664
|
+
}();
|
|
665
|
+
export { RbtObject as default };
|
package/dist/rbt_user.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports["default"] = void 0;
|
|
7
|
-
var _lodash = _interopRequireDefault(require("lodash"));
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
9
1
|
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 }; })(); }
|
|
10
2
|
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); }
|
|
11
3
|
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); }
|
|
@@ -25,7 +17,8 @@ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o =
|
|
|
25
17
|
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
26
18
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
27
19
|
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); }
|
|
28
|
-
|
|
20
|
+
import _ from 'lodash';
|
|
21
|
+
var RbtUser = /*#__PURE__*/function () {
|
|
29
22
|
function RbtUser(record, axiosInstance) {
|
|
30
23
|
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
31
24
|
_classCallCheck(this, RbtUser);
|
|
@@ -46,7 +39,7 @@ var RbtUser = exports["default"] = /*#__PURE__*/function () {
|
|
|
46
39
|
return _createClass(RbtUser, [{
|
|
47
40
|
key: "get",
|
|
48
41
|
value: function get(path) {
|
|
49
|
-
return
|
|
42
|
+
return _.get(this._data, path);
|
|
50
43
|
}
|
|
51
44
|
}, {
|
|
52
45
|
key: "getData",
|
|
@@ -64,9 +57,9 @@ var RbtUser = exports["default"] = /*#__PURE__*/function () {
|
|
|
64
57
|
}, {
|
|
65
58
|
key: "set",
|
|
66
59
|
value: function set(path, value) {
|
|
67
|
-
var currentValue =
|
|
68
|
-
if (!
|
|
69
|
-
|
|
60
|
+
var currentValue = _.get(this._data, path);
|
|
61
|
+
if (!_.isEqual(currentValue, value)) {
|
|
62
|
+
_.set(this._data, path, value);
|
|
70
63
|
this._addChange(path);
|
|
71
64
|
}
|
|
72
65
|
}
|
|
@@ -78,8 +71,8 @@ var RbtUser = exports["default"] = /*#__PURE__*/function () {
|
|
|
78
71
|
throw new Error('setData expects an object');
|
|
79
72
|
}
|
|
80
73
|
Object.keys(newData).forEach(function (key) {
|
|
81
|
-
if (!
|
|
82
|
-
|
|
74
|
+
if (!_.isEqual(_.get(_this._data, key), newData[key])) {
|
|
75
|
+
_.set(_this._data, key, newData[key]);
|
|
83
76
|
_this._addChange(key);
|
|
84
77
|
}
|
|
85
78
|
});
|
|
@@ -134,7 +127,7 @@ var RbtUser = exports["default"] = /*#__PURE__*/function () {
|
|
|
134
127
|
key: "clone",
|
|
135
128
|
value: function clone() {
|
|
136
129
|
// Create a deep copy of the current object's data
|
|
137
|
-
var clonedData =
|
|
130
|
+
var clonedData = _.cloneDeep(this._internalData);
|
|
138
131
|
|
|
139
132
|
// Reset unique identifiers to ensure a new ID is generated upon saving
|
|
140
133
|
delete clonedData.id;
|
|
@@ -238,4 +231,5 @@ var RbtUser = exports["default"] = /*#__PURE__*/function () {
|
|
|
238
231
|
// }
|
|
239
232
|
//}
|
|
240
233
|
}]);
|
|
241
|
-
}();
|
|
234
|
+
}();
|
|
235
|
+
export { RbtUser as default };
|
package/package.json
CHANGED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cookie-based storage adaptor for roboto-js
|
|
3
|
+
* Provides a localStorage-compatible interface using cookies
|
|
4
|
+
* This enables server-side access to authentication tokens
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export default class CookieStorageAdaptor {
|
|
8
|
+
constructor(options = {}) {
|
|
9
|
+
this.options = {
|
|
10
|
+
// Security settings
|
|
11
|
+
secure: options.secure ?? (typeof window !== 'undefined' && window.location.protocol === 'https:'),
|
|
12
|
+
sameSite: options.sameSite ?? 'Lax',
|
|
13
|
+
httpOnly: false, // Must be false so client-side JS can access
|
|
14
|
+
|
|
15
|
+
// Cookie settings
|
|
16
|
+
path: options.path ?? '/',
|
|
17
|
+
maxAge: options.maxAge ?? 24 * 60 * 60, // 24 hours default
|
|
18
|
+
domain: options.domain ?? undefined, // Let browser determine domain
|
|
19
|
+
|
|
20
|
+
// Prefix for roboto cookies to avoid conflicts
|
|
21
|
+
prefix: options.prefix ?? 'rbt_',
|
|
22
|
+
|
|
23
|
+
// Keys that should be stored without prefix for server-side access
|
|
24
|
+
serverAccessKeys: options.serverAccessKeys ?? ['authtoken', 'accessKey', 'apikey'],
|
|
25
|
+
|
|
26
|
+
...options
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
console.log('[CookieStorageAdaptor] Initialized with options:', {
|
|
30
|
+
secure: this.options.secure,
|
|
31
|
+
sameSite: this.options.sameSite,
|
|
32
|
+
path: this.options.path,
|
|
33
|
+
maxAge: this.options.maxAge,
|
|
34
|
+
domain: this.options.domain,
|
|
35
|
+
prefix: this.options.prefix,
|
|
36
|
+
serverAccessKeys: this.options.serverAccessKeys
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get item from cookies (localStorage-compatible interface)
|
|
42
|
+
*/
|
|
43
|
+
async getItem(key) {
|
|
44
|
+
if (typeof document === 'undefined') {
|
|
45
|
+
console.log(`[CookieStorageAdaptor] getItem(${key}): document undefined, returning null`)
|
|
46
|
+
return null
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Check if this key should be stored without prefix for server access
|
|
50
|
+
const usePrefix = !this.options.serverAccessKeys.includes(key)
|
|
51
|
+
const cookieName = usePrefix ? this.options.prefix + key : key
|
|
52
|
+
const name = cookieName + '='
|
|
53
|
+
const decodedCookie = decodeURIComponent(document.cookie)
|
|
54
|
+
const cookies = decodedCookie.split(';')
|
|
55
|
+
|
|
56
|
+
console.log(`[CookieStorageAdaptor] getItem(${key}): looking for cookie "${cookieName}" ${usePrefix ? '(prefixed)' : '(server-accessible)'}`)
|
|
57
|
+
console.log(`[CookieStorageAdaptor] Available cookies:`, cookies.map(c => c.trim().split('=')[0]).join(', '))
|
|
58
|
+
|
|
59
|
+
for (let cookie of cookies) {
|
|
60
|
+
cookie = cookie.trim()
|
|
61
|
+
if (cookie.indexOf(name) === 0) {
|
|
62
|
+
const rawValue = cookie.substring(name.length, cookie.length)
|
|
63
|
+
console.log(`[CookieStorageAdaptor] Found cookie "${cookieName}" with raw value:`, rawValue)
|
|
64
|
+
|
|
65
|
+
// Handle JSON values (like rbtUser)
|
|
66
|
+
try {
|
|
67
|
+
const parsedValue = JSON.parse(rawValue)
|
|
68
|
+
console.log(`[CookieStorageAdaptor] getItem(${key}): returning parsed JSON:`, parsedValue)
|
|
69
|
+
return parsedValue
|
|
70
|
+
} catch {
|
|
71
|
+
console.log(`[CookieStorageAdaptor] getItem(${key}): returning string value:`, rawValue)
|
|
72
|
+
return rawValue
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
console.log(`[CookieStorageAdaptor] getItem(${key}): cookie "${cookieName}" not found, returning null`)
|
|
78
|
+
return null
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Set item in cookies (localStorage-compatible interface)
|
|
83
|
+
*/
|
|
84
|
+
async setItem(key, value) {
|
|
85
|
+
if (typeof document === 'undefined') {
|
|
86
|
+
console.log(`[CookieStorageAdaptor] setItem(${key}): document undefined, skipping`)
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Check if this key should be stored without prefix for server access
|
|
91
|
+
const usePrefix = !this.options.serverAccessKeys.includes(key)
|
|
92
|
+
const cookieName = usePrefix ? this.options.prefix + key : key
|
|
93
|
+
|
|
94
|
+
// Stringify objects/arrays like localStorage does
|
|
95
|
+
const cookieValue = typeof value === 'object' ? JSON.stringify(value) : String(value)
|
|
96
|
+
|
|
97
|
+
console.log(`[CookieStorageAdaptor] setItem(${key}): storing as "${cookieName}" ${usePrefix ? '(prefixed)' : '(server-accessible)'}`)
|
|
98
|
+
console.log(`[CookieStorageAdaptor] Original value:`, value)
|
|
99
|
+
console.log(`[CookieStorageAdaptor] Cookie value:`, cookieValue)
|
|
100
|
+
|
|
101
|
+
// Build cookie string with security options
|
|
102
|
+
const secureFlag = this.options.secure ? '; Secure' : ''
|
|
103
|
+
const domainFlag = this.options.domain ? `; Domain=${this.options.domain}` : ''
|
|
104
|
+
const httpOnlyFlag = this.options.httpOnly ? '; HttpOnly' : ''
|
|
105
|
+
|
|
106
|
+
const cookieString = `${cookieName}=${encodeURIComponent(cookieValue)}; path=${this.options.path}; max-age=${this.options.maxAge}; SameSite=${this.options.sameSite}${secureFlag}${domainFlag}${httpOnlyFlag}`
|
|
107
|
+
|
|
108
|
+
console.log(`[CookieStorageAdaptor] Full cookie string:`, cookieString)
|
|
109
|
+
|
|
110
|
+
document.cookie = cookieString
|
|
111
|
+
|
|
112
|
+
// Verify the cookie was set by immediately reading it back
|
|
113
|
+
const verification = await this.getItem(key)
|
|
114
|
+
if (verification !== null) {
|
|
115
|
+
console.log(`[CookieStorageAdaptor] ✅ Successfully set and verified cookie: ${cookieName}`)
|
|
116
|
+
} else {
|
|
117
|
+
console.error(`[CookieStorageAdaptor] ❌ Failed to set cookie: ${cookieName}`)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Remove item from cookies (localStorage-compatible interface)
|
|
123
|
+
*/
|
|
124
|
+
async removeItem(key) {
|
|
125
|
+
if (typeof document === 'undefined') {
|
|
126
|
+
console.log(`[CookieStorageAdaptor] removeItem(${key}): document undefined, skipping`)
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Check if this key should be stored without prefix for server access
|
|
131
|
+
const usePrefix = !this.options.serverAccessKeys.includes(key)
|
|
132
|
+
const cookieName = usePrefix ? this.options.prefix + key : key
|
|
133
|
+
|
|
134
|
+
console.log(`[CookieStorageAdaptor] removeItem(${key}): removing cookie "${cookieName}" ${usePrefix ? '(prefixed)' : '(server-accessible)'}`)
|
|
135
|
+
|
|
136
|
+
// Check if cookie exists before removal
|
|
137
|
+
const existingValue = await this.getItem(key)
|
|
138
|
+
if (existingValue !== null) {
|
|
139
|
+
console.log(`[CookieStorageAdaptor] Cookie "${cookieName}" exists, removing...`)
|
|
140
|
+
} else {
|
|
141
|
+
console.log(`[CookieStorageAdaptor] Cookie "${cookieName}" doesn't exist, removal not needed`)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const secureFlag = this.options.secure ? '; Secure' : ''
|
|
145
|
+
const domainFlag = this.options.domain ? `; Domain=${this.options.domain}` : ''
|
|
146
|
+
|
|
147
|
+
const removalString = `${cookieName}=; path=${this.options.path}; expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=${this.options.sameSite}${secureFlag}${domainFlag}`
|
|
148
|
+
console.log(`[CookieStorageAdaptor] Removal cookie string:`, removalString)
|
|
149
|
+
|
|
150
|
+
document.cookie = removalString
|
|
151
|
+
|
|
152
|
+
// Verify the cookie was removed
|
|
153
|
+
const verification = await this.getItem(key)
|
|
154
|
+
if (verification === null) {
|
|
155
|
+
console.log(`[CookieStorageAdaptor] ✅ Successfully removed cookie: ${cookieName}`)
|
|
156
|
+
} else {
|
|
157
|
+
console.error(`[CookieStorageAdaptor] ❌ Failed to remove cookie: ${cookieName}, still has value:`, verification)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Clear all roboto cookies
|
|
163
|
+
*/
|
|
164
|
+
async clear() {
|
|
165
|
+
if (typeof document === 'undefined') return
|
|
166
|
+
|
|
167
|
+
// Get all cookies and remove ones with our prefix or server access keys
|
|
168
|
+
const cookies = document.cookie.split(';')
|
|
169
|
+
const prefix = this.options.prefix
|
|
170
|
+
|
|
171
|
+
for (let cookie of cookies) {
|
|
172
|
+
const cookieName = cookie.split('=')[0].trim()
|
|
173
|
+
|
|
174
|
+
// Remove prefixed cookies
|
|
175
|
+
if (cookieName.startsWith(prefix)) {
|
|
176
|
+
const key = cookieName.substring(prefix.length)
|
|
177
|
+
await this.removeItem(key)
|
|
178
|
+
}
|
|
179
|
+
// Remove server access keys (non-prefixed)
|
|
180
|
+
else if (this.options.serverAccessKeys.includes(cookieName)) {
|
|
181
|
+
await this.removeItem(cookieName)
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Get all keys (for debugging/compatibility)
|
|
188
|
+
*/
|
|
189
|
+
async keys() {
|
|
190
|
+
if (typeof document === 'undefined') return []
|
|
191
|
+
|
|
192
|
+
const cookies = document.cookie.split(';')
|
|
193
|
+
const prefix = this.options.prefix
|
|
194
|
+
const keys = []
|
|
195
|
+
|
|
196
|
+
for (let cookie of cookies) {
|
|
197
|
+
const cookieName = cookie.split('=')[0].trim()
|
|
198
|
+
|
|
199
|
+
// Add prefixed cookies
|
|
200
|
+
if (cookieName.startsWith(prefix)) {
|
|
201
|
+
keys.push(cookieName.substring(prefix.length))
|
|
202
|
+
}
|
|
203
|
+
// Add server access keys (non-prefixed)
|
|
204
|
+
else if (this.options.serverAccessKeys.includes(cookieName)) {
|
|
205
|
+
keys.push(cookieName)
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return keys
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Debug method to log all current cookies and adapter state
|
|
214
|
+
*/
|
|
215
|
+
debugState() {
|
|
216
|
+
if (typeof document === 'undefined') {
|
|
217
|
+
console.log('[CookieStorageAdaptor] DEBUG: document undefined (server-side)')
|
|
218
|
+
return
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
console.log('[CookieStorageAdaptor] DEBUG STATE:')
|
|
222
|
+
console.log('- Options:', this.options)
|
|
223
|
+
console.log('- All cookies:', document.cookie)
|
|
224
|
+
|
|
225
|
+
const cookies = document.cookie.split(';')
|
|
226
|
+
const robotoKeys = []
|
|
227
|
+
const serverKeys = []
|
|
228
|
+
const otherKeys = []
|
|
229
|
+
|
|
230
|
+
for (let cookie of cookies) {
|
|
231
|
+
const cookieName = cookie.split('=')[0].trim()
|
|
232
|
+
if (cookieName.startsWith(this.options.prefix)) {
|
|
233
|
+
robotoKeys.push(cookieName)
|
|
234
|
+
} else if (this.options.serverAccessKeys.includes(cookieName)) {
|
|
235
|
+
serverKeys.push(cookieName)
|
|
236
|
+
} else if (cookieName) {
|
|
237
|
+
otherKeys.push(cookieName)
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
console.log('- Roboto prefixed cookies:', robotoKeys)
|
|
242
|
+
console.log('- Server access cookies:', serverKeys)
|
|
243
|
+
console.log('- Other cookies:', otherKeys)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
}
|