@bringg/dashboard-sdk 10.2.1 → 10.2.3-pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8300,13 +8300,15 @@ exports["default"] = CustomAttributesEntity;
8300
8300
  "use strict";
8301
8301
 
8302
8302
  Object.defineProperty(exports, "__esModule", ({ value: true }));
8303
- exports.RealtimeEvents = void 0;
8303
+ exports.WAYPOINT_CUSTOMER_FROM_STORE_FF = exports.RealtimeEvents = void 0;
8304
8304
  var RealtimeEvents;
8305
8305
  (function (RealtimeEvents) {
8306
8306
  RealtimeEvents["Created"] = "customer created";
8307
8307
  RealtimeEvents["Updated"] = "customer update";
8308
8308
  RealtimeEvents["Deleted"] = "customer delete";
8309
8309
  })(RealtimeEvents = exports.RealtimeEvents || (exports.RealtimeEvents = {}));
8310
+ /** Feature flag of the waypoint customer from the customers store (bringg-frontend, Angular, dashboard-sdk). */
8311
+ exports.WAYPOINT_CUSTOMER_FROM_STORE_FF = 'enable_waypoint_customer_from_store';
8310
8312
  //# sourceMappingURL=Customer.consts.js.map
8311
8313
 
8312
8314
  /***/ }),
@@ -8368,10 +8370,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
8368
8370
  };
8369
8371
  Object.defineProperty(exports, "__esModule", ({ value: true }));
8370
8372
  var lodash_1 = __importDefault(__webpack_require__(96486));
8373
+ var data_store_with_signals_1 = __importDefault(__webpack_require__(56692));
8371
8374
  var merge_mapper_1 = __webpack_require__(59200);
8372
8375
  var storable_realtime_subscriptions_1 = __importDefault(__webpack_require__(1227));
8373
8376
  var data_entity_1 = __webpack_require__(91083);
8374
- var data_store_1 = __importDefault(__webpack_require__(73135));
8375
8377
  var storable_data_service_1 = __importDefault(__webpack_require__(45297));
8376
8378
  var array_utils_1 = __webpack_require__(43052);
8377
8379
  var Customer_consts_1 = __webpack_require__(85240);
@@ -8379,7 +8381,8 @@ var customers_service_1 = __importDefault(__webpack_require__(52639));
8379
8381
  var CustomersApi = /** @class */ (function () {
8380
8382
  function CustomersApi(session) {
8381
8383
  var _this = this;
8382
- this.customersStore = new data_store_1.default(undefined, { shallow: true });
8384
+ this.session = session;
8385
+ this.customersStore = new data_store_with_signals_1.default('customersStore');
8383
8386
  this.customersService = new customers_service_1.default(session);
8384
8387
  this.storableDataService = new storable_data_service_1.default(this.customersStore, function (customer) {
8385
8388
  return merge_mapper_1.mergeMapper.mergeIntoExisting(_this.customersStore, customer);
@@ -8398,8 +8401,18 @@ var CustomersApi = /** @class */ (function () {
8398
8401
  CustomersApi.prototype.onCreate = function (callback) {
8399
8402
  return this.storableRealtimeSubscriptions.onEvent(Customer_consts_1.RealtimeEvents.Created, function (item) { return callback(item.current); });
8400
8403
  };
8404
+ /**
8405
+ * Self-push: Angular pushes back the stored customer object after the tasks merge changed it in place, so the merge
8406
+ * finds no diff and `set` reports the change. Cost: every such push re-renders that customer's views even with no
8407
+ * change. Remove it with the Angular pushes once customer realtime events and this flag are on.
8408
+ */
8401
8409
  CustomersApi.prototype.add = function (customer) {
8402
- return this.storableDataService.updateInStores(customer);
8410
+ var isSelfPush = this.customersStore.allItems[customer.id] === customer;
8411
+ var mapped = this.storableDataService.updateInStores(customer);
8412
+ if (isSelfPush && isWaypointCustomerFromStoreEnabled(this.session)) {
8413
+ this.customersStore.set(customer);
8414
+ }
8415
+ return mapped;
8403
8416
  };
8404
8417
  CustomersApi.prototype.getAll = function () {
8405
8418
  return this.customersStore.getAll();
@@ -8407,6 +8420,16 @@ var CustomersApi = /** @class */ (function () {
8407
8420
  CustomersApi.prototype.get = function (id) {
8408
8421
  return this.customersStore.get(id);
8409
8422
  };
8423
+ /**
8424
+ * A number that grows each time the customer changes. The customer object stays the same after an update,
8425
+ * so an observer render puts this value in its memo dependencies to rebuild what it derives from the customer.
8426
+ * A computed that returns the customer object must also return this value, or MobX passes no change on.
8427
+ * @param id - Customer id
8428
+ * @returns The customer's change version (meaningful inside an observer render)
8429
+ */
8430
+ CustomersApi.prototype.getVersion = function (id) {
8431
+ return this.customersStore.getVersion(id);
8432
+ };
8410
8433
  CustomersApi.prototype.loadAll = function (params, options) {
8411
8434
  var _this = this;
8412
8435
  if (options === void 0) { options = data_entity_1.DEFAULT_OPTIONS; }
@@ -8480,6 +8503,10 @@ var CustomersApi = /** @class */ (function () {
8480
8503
  return CustomersApi;
8481
8504
  }());
8482
8505
  exports["default"] = CustomersApi;
8506
+ function isWaypointCustomerFromStoreEnabled(session) {
8507
+ var _a, _b;
8508
+ return Boolean((_b = (_a = session.user) === null || _a === void 0 ? void 0 : _a.feature_flags) === null || _b === void 0 ? void 0 : _b[Customer_consts_1.WAYPOINT_CUSTOMER_FROM_STORE_FF]);
8509
+ }
8483
8510
  //# sourceMappingURL=customers-api.js.map
8484
8511
 
8485
8512
  /***/ }),
@@ -8979,6 +9006,282 @@ exports["default"] = Dashboard;
8979
9006
 
8980
9007
  /***/ }),
8981
9008
 
9009
+ /***/ 56692:
9010
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
9011
+
9012
+ "use strict";
9013
+
9014
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9015
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9016
+ };
9017
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
9018
+ var data_store_1 = __importDefault(__webpack_require__(73135));
9019
+ var item_change_signals_1 = __importDefault(__webpack_require__(5508));
9020
+ /**
9021
+ * A shallow `DataStore` whose MobX reactions re-run when an item they read is added, changed or removed.
9022
+ * Items stay plain objects. Readers report what they read, writers fire the signals, the inner store holds the data.
9023
+ */
9024
+ var DataStoreWithSignals = /** @class */ (function () {
9025
+ /**
9026
+ * @param storeId - Store name for the MobX atom names, for example `customersStore`
9027
+ * @param groupFilters - Passed to the inner `DataStore`
9028
+ */
9029
+ function DataStoreWithSignals(storeId, groupFilters) {
9030
+ if (groupFilters === void 0) { groupFilters = []; }
9031
+ this.store = new data_store_1.default(groupFilters, { shallow: true });
9032
+ this.signals = new item_change_signals_1.default(storeId);
9033
+ }
9034
+ Object.defineProperty(DataStoreWithSignals.prototype, "allItems", {
9035
+ /** The inner items by id. Reading it subscribes nothing: use it in writers, never in views. */
9036
+ get: function () {
9037
+ return this.store.allItems;
9038
+ },
9039
+ enumerable: false,
9040
+ configurable: true
9041
+ });
9042
+ DataStoreWithSignals.prototype.get = function (id) {
9043
+ this.signals.observe(id);
9044
+ return this.store.get(id);
9045
+ };
9046
+ /**
9047
+ * A number that grows each time the item changes. Use it in memo dependencies of an observer render, because the
9048
+ * item object itself stays the same after an update. A computed that returns the item object must also return this
9049
+ * value, or MobX sees the same object and passes no change on.
9050
+ */
9051
+ DataStoreWithSignals.prototype.getVersion = function (id) {
9052
+ return this.signals.version(id);
9053
+ };
9054
+ DataStoreWithSignals.prototype.getAll = function () {
9055
+ this.signals.observeAll();
9056
+ return this.store.getAll();
9057
+ };
9058
+ DataStoreWithSignals.prototype.getGroup = function (group, groupValue) {
9059
+ this.signals.observeAll();
9060
+ return this.store.getGroup(group, groupValue);
9061
+ };
9062
+ DataStoreWithSignals.prototype.isGroupInitialized = function (groupType, groupValue) {
9063
+ return this.store.isGroupInitialized(groupType, groupValue);
9064
+ };
9065
+ DataStoreWithSignals.prototype.set = function (item) {
9066
+ this.store.set(item);
9067
+ this.signals.notify([item.id]);
9068
+ };
9069
+ DataStoreWithSignals.prototype.remove = function (id) {
9070
+ this.store.remove(id);
9071
+ this.signals.notify([id]);
9072
+ };
9073
+ DataStoreWithSignals.prototype.setMany = function (items) {
9074
+ this.store.setMany(items);
9075
+ this.signals.notify(items.filter(isChanged).map(function (item) { return item.current.id; }));
9076
+ };
9077
+ DataStoreWithSignals.prototype.setAll = function (items) {
9078
+ this.store.setAll(items);
9079
+ this.signals.notifyAllObserved();
9080
+ };
9081
+ DataStoreWithSignals.prototype.setGroup = function (groupType, groupValue, items) {
9082
+ this.store.setGroup(groupType, groupValue, items);
9083
+ this.signals.notifyAllObserved();
9084
+ };
9085
+ Object.defineProperty(DataStoreWithSignals.prototype, "observedItemsCount", {
9086
+ /** @internal Number of items that reactions observe right now. For tests. */
9087
+ get: function () {
9088
+ return this.signals.observedCount;
9089
+ },
9090
+ enumerable: false,
9091
+ configurable: true
9092
+ });
9093
+ return DataStoreWithSignals;
9094
+ }());
9095
+ exports["default"] = DataStoreWithSignals;
9096
+ // No diff = a new item. An empty diff = nothing changed.
9097
+ function isChanged(item) {
9098
+ return !item.diff || Object.keys(item.diff).length > 0;
9099
+ }
9100
+ //# sourceMappingURL=data-store-with-signals.js.map
9101
+
9102
+ /***/ }),
9103
+
9104
+ /***/ 5508:
9105
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
9106
+
9107
+ "use strict";
9108
+
9109
+ var __values = (this && this.__values) || function(o) {
9110
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
9111
+ if (m) return m.call(o);
9112
+ if (o && typeof o.length === "number") return {
9113
+ next: function () {
9114
+ if (o && i >= o.length) o = void 0;
9115
+ return { value: o && o[i++], done: !o };
9116
+ }
9117
+ };
9118
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
9119
+ };
9120
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
9121
+ var BringgDashboardSDK_1 = __webpack_require__(5655);
9122
+ /**
9123
+ * Per-item change signals for a shallow DataStore: a reaction that reads an id re-runs when that id changes.
9124
+ * Id signals live only while a reaction reads them; other reads watch `anyChange`, so no change is lost (mobx >= 6.7).
9125
+ * Uses only the MobX instance passed at login, so the host app's reactions track it.
9126
+ */
9127
+ var ItemChangeSignals = /** @class */ (function () {
9128
+ /** @param storeId - Store name for the MobX atom names (devtools and spy only), for example `customersStore`. */
9129
+ function ItemChangeSignals(storeId) {
9130
+ this.storeId = storeId;
9131
+ // Keyed by Number(id): stores accept number-like string ids too.
9132
+ this.entries = new Map();
9133
+ // Store-wide clock: a re-created entry starts here, so an equal version always means no change since.
9134
+ this.seq = 0;
9135
+ }
9136
+ /** Reports a read of `id`. Subscribes the current reaction to changes of that id. */
9137
+ ItemChangeSignals.prototype.observe = function (id) {
9138
+ this.track(id);
9139
+ };
9140
+ /** Reports a read of the whole store (list readers). Subscribes the current reaction to every change. */
9141
+ ItemChangeSignals.prototype.observeAll = function () {
9142
+ if (getMobx()) {
9143
+ this.getAnyChange().reportObserved();
9144
+ }
9145
+ };
9146
+ /**
9147
+ * Version of `id`: grows on every signal of that id. Meaningful only inside a reaction (it subscribes it);
9148
+ * outside a reaction it returns the store-wide counter, so a memo keyed by it is never stale.
9149
+ */
9150
+ ItemChangeSignals.prototype.version = function (id) {
9151
+ var _a, _b;
9152
+ this.track(id);
9153
+ return (_b = (_a = this.entries.get(Number(id))) === null || _a === void 0 ? void 0 : _a.version) !== null && _b !== void 0 ? _b : this.seq;
9154
+ };
9155
+ /** Reports a change of each id, in one MobX action, then fires `anyChange` once. */
9156
+ ItemChangeSignals.prototype.notify = function (ids) {
9157
+ var _this = this;
9158
+ if (!ids.length) {
9159
+ return;
9160
+ }
9161
+ this.seq++;
9162
+ if (!this.anyChange && !this.entries.size) {
9163
+ // Nothing was ever observed: no reaction to tell.
9164
+ return;
9165
+ }
9166
+ getMobx().runInAction(function () {
9167
+ var e_1, _a;
9168
+ try {
9169
+ for (var ids_1 = __values(ids), ids_1_1 = ids_1.next(); !ids_1_1.done; ids_1_1 = ids_1.next()) {
9170
+ var id = ids_1_1.value;
9171
+ var entry = _this.entries.get(Number(id));
9172
+ if (entry) {
9173
+ entry.version = _this.seq;
9174
+ entry.atom.reportChanged();
9175
+ }
9176
+ }
9177
+ }
9178
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
9179
+ finally {
9180
+ try {
9181
+ if (ids_1_1 && !ids_1_1.done && (_a = ids_1.return)) _a.call(ids_1);
9182
+ }
9183
+ finally { if (e_1) throw e_1.error; }
9184
+ }
9185
+ _this.getAnyChange().reportChanged();
9186
+ });
9187
+ };
9188
+ /** Reports a change of every observed id (a store reload or a bulk remove). */
9189
+ ItemChangeSignals.prototype.notifyAllObserved = function () {
9190
+ var _this = this;
9191
+ this.seq++;
9192
+ if (!this.anyChange && !this.entries.size) {
9193
+ return;
9194
+ }
9195
+ getMobx().runInAction(function () {
9196
+ var e_2, _a;
9197
+ try {
9198
+ for (var _b = __values(_this.entries.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
9199
+ var entry = _c.value;
9200
+ entry.version = _this.seq;
9201
+ entry.atom.reportChanged();
9202
+ }
9203
+ }
9204
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
9205
+ finally {
9206
+ try {
9207
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
9208
+ }
9209
+ finally { if (e_2) throw e_2.error; }
9210
+ }
9211
+ _this.getAnyChange().reportChanged();
9212
+ });
9213
+ };
9214
+ Object.defineProperty(ItemChangeSignals.prototype, "observedCount", {
9215
+ /** Number of live id entries. For tests only. */
9216
+ get: function () {
9217
+ return this.entries.size;
9218
+ },
9219
+ enumerable: false,
9220
+ configurable: true
9221
+ });
9222
+ ItemChangeSignals.prototype.track = function (id) {
9223
+ if (id === undefined || id === null || !getMobx()) {
9224
+ return;
9225
+ }
9226
+ id = Number(id);
9227
+ // Cheap filter, the probe never fires: false for a read outside any derivation, so no atom is created on the hot path.
9228
+ if (!this.getProbe().reportObserved()) {
9229
+ this.getAnyChange().reportObserved();
9230
+ return;
9231
+ }
9232
+ var entry = this.entries.get(id);
9233
+ var isNew = !entry;
9234
+ if (isNew) {
9235
+ entry = this.createEntry(id);
9236
+ }
9237
+ // Exact check: false for a new atom read by a computed evaluated inside an action (no reaction behind it).
9238
+ // MobX never calls the unobserve callback of such an atom, so the entry would leak; watch `anyChange` instead.
9239
+ if (!entry.atom.reportObserved()) {
9240
+ if (isNew) {
9241
+ this.entries.delete(id);
9242
+ }
9243
+ this.getAnyChange().reportObserved();
9244
+ }
9245
+ };
9246
+ ItemChangeSignals.prototype.createEntry = function (id) {
9247
+ var _this = this;
9248
+ // The callback reads `entry` only when MobX calls it, at the end of a batch after the last observer left,
9249
+ // never during `createAtom`.
9250
+ var entry = {
9251
+ version: this.seq,
9252
+ atom: getMobx().createAtom("".concat(this.storeId, ".item.").concat(id), undefined, function () {
9253
+ if (_this.entries.get(id) === entry) {
9254
+ _this.entries.delete(id);
9255
+ }
9256
+ })
9257
+ };
9258
+ this.entries.set(id, entry);
9259
+ return entry;
9260
+ };
9261
+ ItemChangeSignals.prototype.getProbe = function () {
9262
+ if (!this.probe) {
9263
+ this.probe = getMobx().createAtom("".concat(this.storeId, ".probe"));
9264
+ }
9265
+ return this.probe;
9266
+ };
9267
+ ItemChangeSignals.prototype.getAnyChange = function () {
9268
+ if (!this.anyChange) {
9269
+ this.anyChange = getMobx().createAtom("".concat(this.storeId, ".anyChange"));
9270
+ }
9271
+ return this.anyChange;
9272
+ };
9273
+ return ItemChangeSignals;
9274
+ }());
9275
+ exports["default"] = ItemChangeSignals;
9276
+ // Null before login (globals are set by `BringgDashboardSDK.login`): no MobX, so no reaction can observe anything.
9277
+ function getMobx() {
9278
+ var _a;
9279
+ return (_a = (0, BringgDashboardSDK_1.getGlobals)()) === null || _a === void 0 ? void 0 : _a.mobx;
9280
+ }
9281
+ //# sourceMappingURL=item-change-signals.js.map
9282
+
9283
+ /***/ }),
9284
+
8982
9285
  /***/ 93670:
8983
9286
  /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
8984
9287
 
@@ -25231,7 +25534,7 @@ var BringgException_1 = __webpack_require__(43605);
25231
25534
  var client_page_1 = __webpack_require__(16573);
25232
25535
  var Logger_1 = __importDefault(__webpack_require__(55860));
25233
25536
  var abort_1 = __webpack_require__(34179);
25234
- var version = '10.2.1';
25537
+ var version = '10.2.3-pre.1';
25235
25538
  function logErrorResponse(response) {
25236
25539
  var data = response.data, status = response.status;
25237
25540
  try {