@bringg/dashboard-sdk 9.77.1 → 9.77.3-pre

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.
@@ -3069,18 +3069,19 @@ var BringgDashboardSDK = /** @class */ (function () {
3069
3069
  exports.BringgDashboardSDK = BringgDashboardSDK;
3070
3070
  function init(session) {
3071
3071
  return __awaiter(this, void 0, void 0, function () {
3072
- var bringg, workflows, taskRejectReasons;
3072
+ var bringg, customersApi, workflows, taskRejectReasons;
3073
3073
  return __generator(this, function (_a) {
3074
3074
  switch (_a.label) {
3075
3075
  case 0:
3076
3076
  bringg = new BringgDashboardSDK(session);
3077
+ customersApi = new customers_api_1.default(session);
3077
3078
  bringg.v2 = {
3078
3079
  vehicles: new vehicles_api_1.default(session),
3079
3080
  relay: new RelayApi_1.default(session),
3080
- tasks: new tasks_api_1.default(session),
3081
+ tasks: new tasks_api_1.default(session, customersApi),
3081
3082
  users: new users_api_1.default(session),
3082
3083
  tags: new tags_api_1.default(session),
3083
- customers: new customers_api_1.default(session),
3084
+ customers: customersApi,
3084
3085
  plannedDeliveryWindows: new planned_delivery_windows_api_1.default(session),
3085
3086
  optimizationResultApi: new optimization_result_api_1.default(session),
3086
3087
  exclusionWindow: new exclusion_window_api_1.ExclusionWindowApi(session),
@@ -8269,6 +8270,17 @@ exports.objectMerger = { deepMerge: deepMerge };
8269
8270
 
8270
8271
  "use strict";
8271
8272
 
8273
+ var __assign = (this && this.__assign) || function () {
8274
+ __assign = Object.assign || function(t) {
8275
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
8276
+ s = arguments[i];
8277
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
8278
+ t[p] = s[p];
8279
+ }
8280
+ return t;
8281
+ };
8282
+ return __assign.apply(this, arguments);
8283
+ };
8272
8284
  var __values = (this && this.__values) || function(o) {
8273
8285
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
8274
8286
  if (m) return m.call(o);
@@ -8299,6 +8311,7 @@ var StorableRealtimeSubscriptions = /** @class */ (function () {
8299
8311
  if (subEntityEvents === void 0) { subEntityEvents = []; }
8300
8312
  var _loop_1 = function (event_1) {
8301
8313
  this_1.realtimeSubscriptions.subscribe(event_1.name, function (item) {
8314
+ var _a, _b;
8302
8315
  item = event_1.itemExtractor ? event_1.itemExtractor(item) : item;
8303
8316
  var data = event_1.extraDataFunc && event_1.extraDataFunc(item);
8304
8317
  if (data === null || data === void 0 ? void 0 : data.ignore) {
@@ -8315,10 +8328,16 @@ var StorableRealtimeSubscriptions = /** @class */ (function () {
8315
8328
  var skipStoreUpdate = !!(data === null || data === void 0 ? void 0 : data.skipStoreUpdate);
8316
8329
  if (skipStoreUpdate) {
8317
8330
  var mappedStorableItem = _this.storableDataService.mapItem(item, data === null || data === void 0 ? void 0 : data.params);
8331
+ // Cache layer: reconcile dependent cached entities even when this entity itself is
8332
+ // not stored (e.g. a not-yet-cached trailer moving between cached trucks).
8333
+ (_a = event_1.onAfterStoreSync) === null || _a === void 0 ? void 0 : _a.call(event_1, mappedStorableItem);
8318
8334
  _this.runEventCallbacks(event_1.name, mappedStorableItem, { skipStoreUpdate: skipStoreUpdate });
8319
8335
  }
8320
8336
  else {
8321
8337
  var mappedStorableItem = _this.storableDataService.updateInStores(item, undefined, undefined, data === null || data === void 0 ? void 0 : data.params);
8338
+ // Cache layer: let the entity reconcile dependent cached entities before any consumer
8339
+ // is notified, so the whole store is consistent when store events fire.
8340
+ (_b = event_1.onAfterStoreSync) === null || _b === void 0 ? void 0 : _b.call(event_1, mappedStorableItem);
8322
8341
  _this.runEventCallbacks(event_1.name, mappedStorableItem);
8323
8342
  }
8324
8343
  }
@@ -8340,11 +8359,75 @@ var StorableRealtimeSubscriptions = /** @class */ (function () {
8340
8359
  }
8341
8360
  var _loop_2 = function (subEntityEvent) {
8342
8361
  this_2.realtimeSubscriptions.subscribe(subEntityEvent.name, function (subEntityEventData) {
8362
+ var e_3, _a;
8363
+ var _b, _c;
8343
8364
  subEntityEvent.ignoreFields.forEach(function (field) { return delete subEntityEventData[field]; });
8365
+ var parentId = subEntityEventData[subEntityEvent.parentField];
8366
+ var entityId = subEntityEventData[subEntityEvent.idField || 'id'];
8367
+ var getParent = function () { return _this.dataStore.get(parentId); };
8368
+ var pendingEnrichers = [];
8369
+ if (subEntityEvent.enrich) {
8370
+ var activeEnrichers = subEntityEvent.enrich.enrichers.filter(function (e) {
8371
+ return e.shouldEnrich(subEntityEventData, getParent);
8372
+ });
8373
+ try {
8374
+ for (var activeEnrichers_1 = (e_3 = void 0, __values(activeEnrichers)), activeEnrichers_1_1 = activeEnrichers_1.next(); !activeEnrichers_1_1.done; activeEnrichers_1_1 = activeEnrichers_1.next()) {
8375
+ var enricher = activeEnrichers_1_1.value;
8376
+ var result = (_c = (_b = enricher.resolveSync) === null || _b === void 0 ? void 0 : _b.call(enricher, subEntityEventData, getParent)) !== null && _c !== void 0 ? _c : null;
8377
+ if (result !== null) {
8378
+ Object.assign(subEntityEventData, result);
8379
+ }
8380
+ else {
8381
+ pendingEnrichers.push(enricher);
8382
+ }
8383
+ }
8384
+ }
8385
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
8386
+ finally {
8387
+ try {
8388
+ if (activeEnrichers_1_1 && !activeEnrichers_1_1.done && (_a = activeEnrichers_1.return)) _a.call(activeEnrichers_1);
8389
+ }
8390
+ finally { if (e_3) throw e_3.error; }
8391
+ }
8392
+ }
8344
8393
  var eventChangeData = _this.changeSubEntity(subEntityEventData, subEntityEvent.idField || 'id', subEntityEvent.parentField, subEntityEvent.field, subEntityEvent.isDelete);
8345
8394
  if (eventChangeData === null || eventChangeData === void 0 ? void 0 : eventChangeData.current) {
8346
8395
  _this.runEventCallbacks(subEntityEvent.eventToRaise, eventChangeData);
8347
8396
  }
8397
+ if (pendingEnrichers.length > 0) {
8398
+ var applyEnrichment_1 = function (data) {
8399
+ var _a;
8400
+ var _b;
8401
+ var parent = _this.dataStore.get(parentId);
8402
+ if (!parent) {
8403
+ return;
8404
+ }
8405
+ var subEntity = (_b = parent[subEntityEvent.field]) === null || _b === void 0 ? void 0 : _b.find(function (e) { return Number(e.id) === Number(entityId); });
8406
+ if (!subEntity) {
8407
+ return;
8408
+ }
8409
+ var oldValues = Object.fromEntries(Object.keys(data).map(function (key) { return [key, subEntity[key]]; }));
8410
+ Object.assign(subEntity, data);
8411
+ _this.runEventCallbacks(subEntityEvent.eventToRaise, {
8412
+ current: parent,
8413
+ diff: (_a = {}, _a[subEntityEvent.field] = [__assign({ id: entityId }, oldValues)], _a)
8414
+ });
8415
+ };
8416
+ // Promise.all is fine here because today there is only one async enricher per event.
8417
+ // If multiple async enrichers are ever added, switch to Promise.allSettled so a
8418
+ // single rejection does not suppress the results of the others.
8419
+ Promise.all(pendingEnrichers.map(function (e) { return e.resolveAsync(subEntityEventData, getParent); }))
8420
+ .then(function (results) {
8421
+ var asyncData = results.reduce(function (acc, result) { return (result !== null ? Object.assign(acc, result) : acc); }, {});
8422
+ if (Object.keys(asyncData).length > 0) {
8423
+ applyEnrichment_1(asyncData);
8424
+ }
8425
+ })
8426
+ .catch(function (err) {
8427
+ console.error('async enrichment failed for', subEntityEvent.field, 'id', entityId);
8428
+ console.error(err);
8429
+ });
8430
+ }
8348
8431
  });
8349
8432
  };
8350
8433
  var this_2 = this;
@@ -23765,7 +23848,7 @@ var lodash_1 = __webpack_require__(96486);
23765
23848
  var BringgException_1 = __webpack_require__(43605);
23766
23849
  var Logger_1 = __importDefault(__webpack_require__(55860));
23767
23850
  var abort_1 = __webpack_require__(34179);
23768
- var version = '9.77.1';
23851
+ var version = '9.77.3-pre';
23769
23852
  function logErrorResponse(response) {
23770
23853
  var data = response.data, status = response.status;
23771
23854
  try {
@@ -26565,6 +26648,42 @@ exports.taskMerger = { mergeTaskIntoExisting: mergeTaskIntoExisting };
26565
26648
 
26566
26649
  "use strict";
26567
26650
 
26651
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26652
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
26653
+ return new (P || (P = Promise))(function (resolve, reject) {
26654
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
26655
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26656
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
26657
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
26658
+ });
26659
+ };
26660
+ var __generator = (this && this.__generator) || function (thisArg, body) {
26661
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
26662
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
26663
+ function verb(n) { return function (v) { return step([n, v]); }; }
26664
+ function step(op) {
26665
+ if (f) throw new TypeError("Generator is already executing.");
26666
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
26667
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
26668
+ if (y = 0, t) op = [op[0] & 2, t.value];
26669
+ switch (op[0]) {
26670
+ case 0: case 1: t = op; break;
26671
+ case 4: _.label++; return { value: op[1], done: false };
26672
+ case 5: _.label++; y = op[1]; op = [0]; continue;
26673
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
26674
+ default:
26675
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26676
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
26677
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
26678
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
26679
+ if (t[2]) _.ops.pop();
26680
+ _.trys.pop(); continue;
26681
+ }
26682
+ op = body.call(thisArg, _);
26683
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
26684
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
26685
+ }
26686
+ };
26568
26687
  var __values = (this && this.__values) || function(o) {
26569
26688
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
26570
26689
  if (m) return m.call(o);
@@ -26580,11 +26699,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26580
26699
  return (mod && mod.__esModule) ? mod : { "default": mod };
26581
26700
  };
26582
26701
  Object.defineProperty(exports, "__esModule", ({ value: true }));
26702
+ var cloneDeep_1 = __importDefault(__webpack_require__(50361));
26583
26703
  var storable_realtime_subscriptions_1 = __importDefault(__webpack_require__(1227));
26584
26704
  var Tasks_consts_1 = __webpack_require__(24976);
26585
26705
  var TaskRealtimeSubscriptions = /** @class */ (function () {
26586
- function TaskRealtimeSubscriptions(session, tasksStore, storableDataService) {
26706
+ function TaskRealtimeSubscriptions(session, tasksStore, storableDataService, customersApi) {
26587
26707
  this.tasksStore = tasksStore;
26708
+ this.customersApi = customersApi;
26588
26709
  this.storableRealtimeSubscriptions = new storable_realtime_subscriptions_1.default(session, tasksStore, storableDataService);
26589
26710
  }
26590
26711
  TaskRealtimeSubscriptions.prototype.updateStoreOnEvents = function () {
@@ -26635,7 +26756,61 @@ var TaskRealtimeSubscriptions = /** @class */ (function () {
26635
26756
  parentField: 'task_id',
26636
26757
  field: 'way_points',
26637
26758
  ignoreFields: ['way_points'],
26638
- isDelete: false
26759
+ isDelete: false,
26760
+ enrich: {
26761
+ enrichers: [
26762
+ /**
26763
+ * Updating customer on a WayPoint is pretty much an edge case
26764
+ * Customer enrichment can be fully removed if way_point.customer is deprecated and marked as such
26765
+ * that must not be used within dSDK data consumers and all existing usages are removed.
26766
+ * This is what we have to do if we want to avoid unnecessary complications on dSDK side.
26767
+ */
26768
+ {
26769
+ shouldEnrich: function (payload, getTask) {
26770
+ var _a, _b, _c;
26771
+ if (!('customer_id' in payload) || 'customer' in payload) {
26772
+ return false;
26773
+ }
26774
+ var wp = (_b = (_a = getTask()) === null || _a === void 0 ? void 0 : _a.way_points) === null || _b === void 0 ? void 0 : _b.find(function (wp) { return Number(wp.id) === Number(payload.id); });
26775
+ return payload.customer_id !== ((_c = wp === null || wp === void 0 ? void 0 : wp.customer) === null || _c === void 0 ? void 0 : _c.id);
26776
+ },
26777
+ resolveSync: function (payload) {
26778
+ if (payload.customer_id === null) {
26779
+ return { customer: null };
26780
+ }
26781
+ var cached = _this.customersApi.get(payload.customer_id);
26782
+ return cached ? { customer: (0, cloneDeep_1.default)(cached) } : null;
26783
+ },
26784
+ resolveAsync: function (payload, getTask) { return __awaiter(_this, void 0, void 0, function () {
26785
+ var payloadCustomerId, wpId, shouldStop, findWp, customer;
26786
+ return __generator(this, function (_a) {
26787
+ switch (_a.label) {
26788
+ case 0:
26789
+ if (payload.customer_id === null) {
26790
+ return [2 /*return*/, null];
26791
+ }
26792
+ payloadCustomerId = Number(payload.customer_id);
26793
+ wpId = Number(payload.id);
26794
+ shouldStop = function (wp) {
26795
+ return !wp || Number(wp.customer_id) !== payloadCustomerId;
26796
+ };
26797
+ findWp = function () { var _a, _b; return (_b = (_a = getTask()) === null || _a === void 0 ? void 0 : _a.way_points) === null || _b === void 0 ? void 0 : _b.find(function (wp) { return wp.id === wpId; }); };
26798
+ if (shouldStop(findWp())) {
26799
+ return [2 /*return*/, null];
26800
+ }
26801
+ return [4 /*yield*/, this.customersApi.load(payload.customer_id)];
26802
+ case 1:
26803
+ customer = _a.sent();
26804
+ if (shouldStop(findWp())) {
26805
+ return [2 /*return*/, null];
26806
+ }
26807
+ return [2 /*return*/, { customer: (0, cloneDeep_1.default)(customer) }];
26808
+ }
26809
+ });
26810
+ }); }
26811
+ }
26812
+ ]
26813
+ }
26639
26814
  },
26640
26815
  {
26641
26816
  name: Tasks_consts_1.TaskRealTimeEvents.WAYPOINT_DELETED,
@@ -26796,7 +26971,7 @@ var tasks_service_1 = __importDefault(__webpack_require__(8159));
26796
26971
  // hard coded fields to take advantage of the light data store cache
26797
26972
  var READY_TO_EXECUTE_FIELDS = ['ready_to_execute'];
26798
26973
  var TasksApi = /** @class */ (function () {
26799
- function TasksApi(session) {
26974
+ function TasksApi(session, customersApi) {
26800
26975
  var _this = this;
26801
26976
  var groupFilters = [
26802
26977
  {
@@ -26837,7 +27012,7 @@ var TasksApi = /** @class */ (function () {
26837
27012
  params: params
26838
27013
  });
26839
27014
  }, [lightDataStore]);
26840
- this.taskRealtimeSubscriptions = new task_realtime_subscriptions_1.default(session, this.tasksStore, this.storableDataService);
27015
+ this.taskRealtimeSubscriptions = new task_realtime_subscriptions_1.default(session, this.tasksStore, this.storableDataService, customersApi);
26841
27016
  }
26842
27017
  TasksApi.prototype.updateStoreOnEvents = function () {
26843
27018
  this.taskRealtimeSubscriptions.updateStoreOnEvents();
@@ -33262,6 +33437,120 @@ exports["default"] = Vehicles;
33262
33437
 
33263
33438
  /***/ }),
33264
33439
 
33440
+ /***/ 25240:
33441
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
33442
+
33443
+ "use strict";
33444
+
33445
+ var __assign = (this && this.__assign) || function () {
33446
+ __assign = Object.assign || function(t) {
33447
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
33448
+ s = arguments[i];
33449
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
33450
+ t[p] = s[p];
33451
+ }
33452
+ return t;
33453
+ };
33454
+ return __assign.apply(this, arguments);
33455
+ };
33456
+ var __importDefault = (this && this.__importDefault) || function (mod) {
33457
+ return (mod && mod.__esModule) ? mod : { "default": mod };
33458
+ };
33459
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
33460
+ var BringgDashboardSDK_1 = __webpack_require__(5655);
33461
+ var storable_realtime_subscriptions_1 = __importDefault(__webpack_require__(1227));
33462
+ var Vehicle_consts_1 = __webpack_require__(84010);
33463
+ var VehicleRealtimeSubscriptions = /** @class */ (function () {
33464
+ function VehicleRealtimeSubscriptions(session, vehiclesStore, storableDataService) {
33465
+ this.vehiclesStore = vehiclesStore;
33466
+ this.storableDataService = storableDataService;
33467
+ this.storableRealtimeSubscriptions = new storable_realtime_subscriptions_1.default(session, vehiclesStore, storableDataService);
33468
+ }
33469
+ VehicleRealtimeSubscriptions.prototype.updateStoreOnEvents = function () {
33470
+ var _this = this;
33471
+ this.storableRealtimeSubscriptions.updateStoreOnEvents([
33472
+ {
33473
+ name: Vehicle_consts_1.REAL_TIME_EVENTS.VEHICLE_UPDATE,
33474
+ isDelete: false,
33475
+ extraDataFunc: function (vehicle) { return ({ skipStoreUpdate: !_this.vehiclesStore.get(vehicle.id) }); },
33476
+ // Reconcile Trailer and affected Trucks after Truck-Trailer link is changed
33477
+ // Remove if / when Trailer-Truck link changes trigger Truck/-s real-time updated events
33478
+ onAfterStoreSync: function (mapped) { return _this.reconcileTrucksOnTrailerChange(mapped); }
33479
+ },
33480
+ { name: Vehicle_consts_1.REAL_TIME_EVENTS.VEHICLE_DELETE, isDelete: true }
33481
+ ]);
33482
+ };
33483
+ VehicleRealtimeSubscriptions.prototype.onUpdate = function (callback) {
33484
+ return this.storableRealtimeSubscriptions.onEvent(Vehicle_consts_1.REAL_TIME_EVENTS.VEHICLE_UPDATE, function (item) { return callback(item.current); });
33485
+ };
33486
+ VehicleRealtimeSubscriptions.prototype.onDelete = function (callback) {
33487
+ return this.storableRealtimeSubscriptions.onEvent(Vehicle_consts_1.REAL_TIME_EVENTS.VEHICLE_DELETE, function (item) { return callback(item.diff); });
33488
+ };
33489
+ VehicleRealtimeSubscriptions.prototype.onUnassigned = function (callback) {
33490
+ return this.storableRealtimeSubscriptions.onAnyEvent(Vehicle_consts_1.REAL_TIME_EVENTS.VEHICLE_UNASSIGNED, function (vehicle) {
33491
+ return callback(vehicle);
33492
+ });
33493
+ };
33494
+ // This should work as expected until Vehicle Update event sends full Vehicle structure
33495
+ // and StorableDataService.mapper maps real-time payload to MappedStorableItem.current
33496
+ VehicleRealtimeSubscriptions.prototype.reconcileTrucksOnTrailerChange = function (_a) {
33497
+ var _this = this;
33498
+ var _b, _c;
33499
+ var trailer = _a.current;
33500
+ // Only a trailer update can change a truck's derived `trailer` field.
33501
+ if (!(trailer === null || trailer === void 0 ? void 0 : trailer.is_trailer)) {
33502
+ return;
33503
+ }
33504
+ // A partial trailer update may omit `truck_id`; only reconcile when the payload carries it
33505
+ // (explicit null = detach, a value = attach). Absent = no connection info -> leave cache as-is,
33506
+ // so a partial update can't be misread as detach and wrongly clear the truck's trailer.
33507
+ if (!('truck_id' in trailer)) {
33508
+ return;
33509
+ }
33510
+ var newTruckId = (_b = trailer.truck_id) !== null && _b !== void 0 ? _b : null;
33511
+ var oldTruck = this.findTruckHoldingTrailer(trailer.id);
33512
+ // No connection change relative to the cache - nothing to reconcile.
33513
+ if (((_c = oldTruck === null || oldTruck === void 0 ? void 0 : oldTruck.id) !== null && _c !== void 0 ? _c : null) === newTruckId) {
33514
+ return;
33515
+ }
33516
+ (0, BringgDashboardSDK_1.getGlobals)().mobx.runInAction(function () {
33517
+ if (oldTruck) {
33518
+ _this.applyTrailerToTruck(oldTruck.id, null);
33519
+ }
33520
+ _this.applyTrailerToTruck(newTruckId, trailer);
33521
+ });
33522
+ };
33523
+ VehicleRealtimeSubscriptions.prototype.findTruckHoldingTrailer = function (trailerId) {
33524
+ return this.vehiclesStore
33525
+ .getGroup(Vehicle_consts_1.VehicleGroup.IsTrailer, false)
33526
+ .find(function (vehicle) { return vehicle.trailer && vehicle.trailer.id === trailerId; });
33527
+ };
33528
+ VehicleRealtimeSubscriptions.prototype.applyTrailerToTruck = function (truckId, trailerEntity) {
33529
+ if (!truckId) {
33530
+ return;
33531
+ }
33532
+ var truck = this.vehiclesStore.get(truckId);
33533
+ // Only reconcile trucks that are actually cached; missing trucks get the correct trailer on load.
33534
+ if (!truck) {
33535
+ return;
33536
+ }
33537
+ var mobx = (0, BringgDashboardSDK_1.getGlobals)().mobx;
33538
+ // Deep, plain, non-observable COPY of the trailerEntity.
33539
+ // Drop the nested trailer's own `trailer` to avoid recursive nesting.
33540
+ var trailerSnapshot = trailerEntity ? __assign(__assign({}, mobx.toJS(trailerEntity)), { trailer: null }) : null;
33541
+ // toJS the truck too so we replace it with a fresh plain object instead of mutating the live
33542
+ // observable in place; updateInStores re-observes it as the truck's own subtree.
33543
+ var updatedTruck = __assign(__assign({}, mobx.toJS(truck)), { trailer: trailerSnapshot });
33544
+ var mapped = this.storableDataService.updateInStores(updatedTruck);
33545
+ this.storableRealtimeSubscriptions.runEventCallbacks(Vehicle_consts_1.REAL_TIME_EVENTS.VEHICLE_UPDATE, mapped);
33546
+ };
33547
+ return VehicleRealtimeSubscriptions;
33548
+ }());
33549
+ exports["default"] = VehicleRealtimeSubscriptions;
33550
+ //# sourceMappingURL=vehicle-realtime-subscriptions.js.map
33551
+
33552
+ /***/ }),
33553
+
33265
33554
  /***/ 57020:
33266
33555
  /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
33267
33556
 
@@ -33320,22 +33609,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33320
33609
  Object.defineProperty(exports, "__esModule", ({ value: true }));
33321
33610
  var types_1 = __webpack_require__(63127);
33322
33611
  var lodash_1 = __webpack_require__(96486);
33323
- var storable_realtime_subscriptions_1 = __importDefault(__webpack_require__(1227));
33324
33612
  var data_entity_1 = __webpack_require__(91083);
33325
33613
  var data_store_1 = __importDefault(__webpack_require__(73135));
33326
33614
  var storable_data_service_1 = __importDefault(__webpack_require__(45297));
33327
33615
  var Vehicle_consts_1 = __webpack_require__(84010);
33616
+ var vehicle_realtime_subscriptions_1 = __importDefault(__webpack_require__(25240));
33328
33617
  var vehicles_service_1 = __importDefault(__webpack_require__(87386));
33329
33618
  var VehiclesApi = /** @class */ (function () {
33330
33619
  function VehiclesApi(session) {
33620
+ var _this = this;
33331
33621
  var groupFilters = [
33332
33622
  { groupType: Vehicle_consts_1.VehicleGroup.Team, keyFunc: function (vehicle) { return vehicle.team_id; } },
33333
33623
  { groupType: Vehicle_consts_1.VehicleGroup.IsTrailer, keyFunc: function (vehicle) { return !!vehicle.is_trailer; } }
33334
33624
  ];
33335
33625
  this.vehiclesStore = new data_store_1.default(groupFilters);
33336
33626
  this.vehiclesService = new vehicles_service_1.default(session);
33337
- this.storableDataService = new storable_data_service_1.default(this.vehiclesStore);
33338
- this.storableRealtimeSubscriptions = new storable_realtime_subscriptions_1.default(session, this.vehiclesStore, this.storableDataService);
33627
+ this.storableDataService = new storable_data_service_1.default(this.vehiclesStore, function (vehicle) { return _this.mapVehicle(vehicle); });
33628
+ this.vehicleRealtimeSubscriptions = new vehicle_realtime_subscriptions_1.default(session, this.vehiclesStore, this.storableDataService);
33339
33629
  }
33340
33630
  VehiclesApi.prototype.load = function (id, options) {
33341
33631
  var _this = this;
@@ -33432,21 +33722,26 @@ var VehiclesApi = /** @class */ (function () {
33432
33722
  return this.storableDataService.modify('create', function () { return _this.vehiclesService.create(vehicleData); });
33433
33723
  };
33434
33724
  VehiclesApi.prototype.updateStoreOnEvents = function () {
33435
- this.storableRealtimeSubscriptions.updateStoreOnEvents([
33436
- { name: Vehicle_consts_1.REAL_TIME_EVENTS.VEHICLE_UPDATE, isDelete: false },
33437
- { name: Vehicle_consts_1.REAL_TIME_EVENTS.VEHICLE_DELETE, isDelete: true }
33438
- ]);
33725
+ this.vehicleRealtimeSubscriptions.updateStoreOnEvents();
33726
+ };
33727
+ // `trailer` is a derived field the reconciler maintains on trucks. Realtime vehicle payloads don't
33728
+ // carry it, so a plain truck update would otherwise REPLACE the cached truck and wipe its trailer.
33729
+ // Preserve the cached `trailer` whenever the incoming payload omits the key; take it from the payload
33730
+ // only when explicitly present (HTTP loads, PUT responses, reconciler writes).
33731
+ VehiclesApi.prototype.mapVehicle = function (vehicle) {
33732
+ var existing = this.vehiclesStore.get(vehicle.id);
33733
+ var current = existing && 'trailer' in existing && !('trailer' in vehicle)
33734
+ ? __assign(__assign({}, vehicle), { trailer: existing.trailer }) : vehicle;
33735
+ return { current: current, diff: existing };
33439
33736
  };
33440
33737
  VehiclesApi.prototype.onUpdate = function (callback) {
33441
- return this.storableRealtimeSubscriptions.onEvent(Vehicle_consts_1.REAL_TIME_EVENTS.VEHICLE_UPDATE, function (item) { return callback(item.current); });
33738
+ return this.vehicleRealtimeSubscriptions.onUpdate(callback);
33442
33739
  };
33443
33740
  VehiclesApi.prototype.onDelete = function (callback) {
33444
- return this.storableRealtimeSubscriptions.onEvent(Vehicle_consts_1.REAL_TIME_EVENTS.VEHICLE_DELETE, function (item) { return callback(item.current); });
33741
+ return this.vehicleRealtimeSubscriptions.onDelete(callback);
33445
33742
  };
33446
33743
  VehiclesApi.prototype.onUnassigned = function (callback) {
33447
- return this.storableRealtimeSubscriptions.onAnyEvent(Vehicle_consts_1.REAL_TIME_EVENTS.VEHICLE_UNASSIGNED, function (vehicle) {
33448
- return callback(vehicle);
33449
- });
33744
+ return this.vehicleRealtimeSubscriptions.onUnassigned(callback);
33450
33745
  };
33451
33746
  VehiclesApi.prototype.get = function (id) {
33452
33747
  return this.vehiclesStore.get(id);