@bringg/dashboard-sdk 9.76.3 → 9.76.4-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);
@@ -8340,11 +8352,75 @@ var StorableRealtimeSubscriptions = /** @class */ (function () {
8340
8352
  }
8341
8353
  var _loop_2 = function (subEntityEvent) {
8342
8354
  this_2.realtimeSubscriptions.subscribe(subEntityEvent.name, function (subEntityEventData) {
8355
+ var e_3, _a;
8356
+ var _b, _c;
8343
8357
  subEntityEvent.ignoreFields.forEach(function (field) { return delete subEntityEventData[field]; });
8358
+ var parentId = subEntityEventData[subEntityEvent.parentField];
8359
+ var entityId = subEntityEventData[subEntityEvent.idField || 'id'];
8360
+ var getParent = function () { return _this.dataStore.get(parentId); };
8361
+ var pendingEnrichers = [];
8362
+ if (subEntityEvent.enrich) {
8363
+ var activeEnrichers = subEntityEvent.enrich.enrichers.filter(function (e) {
8364
+ return e.shouldEnrich(subEntityEventData, getParent);
8365
+ });
8366
+ try {
8367
+ 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()) {
8368
+ var enricher = activeEnrichers_1_1.value;
8369
+ var result = (_c = (_b = enricher.resolveSync) === null || _b === void 0 ? void 0 : _b.call(enricher, subEntityEventData, getParent)) !== null && _c !== void 0 ? _c : null;
8370
+ if (result !== null) {
8371
+ Object.assign(subEntityEventData, result);
8372
+ }
8373
+ else {
8374
+ pendingEnrichers.push(enricher);
8375
+ }
8376
+ }
8377
+ }
8378
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
8379
+ finally {
8380
+ try {
8381
+ if (activeEnrichers_1_1 && !activeEnrichers_1_1.done && (_a = activeEnrichers_1.return)) _a.call(activeEnrichers_1);
8382
+ }
8383
+ finally { if (e_3) throw e_3.error; }
8384
+ }
8385
+ }
8344
8386
  var eventChangeData = _this.changeSubEntity(subEntityEventData, subEntityEvent.idField || 'id', subEntityEvent.parentField, subEntityEvent.field, subEntityEvent.isDelete);
8345
8387
  if (eventChangeData === null || eventChangeData === void 0 ? void 0 : eventChangeData.current) {
8346
8388
  _this.runEventCallbacks(subEntityEvent.eventToRaise, eventChangeData);
8347
8389
  }
8390
+ if (pendingEnrichers.length > 0) {
8391
+ var applyEnrichment_1 = function (data) {
8392
+ var _a;
8393
+ var _b;
8394
+ var parent = _this.dataStore.get(parentId);
8395
+ if (!parent) {
8396
+ return;
8397
+ }
8398
+ var subEntity = (_b = parent[subEntityEvent.field]) === null || _b === void 0 ? void 0 : _b.find(function (e) { return Number(e.id) === Number(entityId); });
8399
+ if (!subEntity) {
8400
+ return;
8401
+ }
8402
+ var oldValues = Object.fromEntries(Object.keys(data).map(function (key) { return [key, subEntity[key]]; }));
8403
+ Object.assign(subEntity, data);
8404
+ _this.runEventCallbacks(subEntityEvent.eventToRaise, {
8405
+ current: parent,
8406
+ diff: (_a = {}, _a[subEntityEvent.field] = [__assign({ id: entityId }, oldValues)], _a)
8407
+ });
8408
+ };
8409
+ // Promise.all is fine here because today there is only one async enricher per event.
8410
+ // If multiple async enrichers are ever added, switch to Promise.allSettled so a
8411
+ // single rejection does not suppress the results of the others.
8412
+ Promise.all(pendingEnrichers.map(function (e) { return e.resolveAsync(subEntityEventData, getParent); }))
8413
+ .then(function (results) {
8414
+ var asyncData = results.reduce(function (acc, result) { return (result !== null ? Object.assign(acc, result) : acc); }, {});
8415
+ if (Object.keys(asyncData).length > 0) {
8416
+ applyEnrichment_1(asyncData);
8417
+ }
8418
+ })
8419
+ .catch(function (err) {
8420
+ console.error('async enrichment failed for', subEntityEvent.field, 'id', entityId);
8421
+ console.error(err);
8422
+ });
8423
+ }
8348
8424
  });
8349
8425
  };
8350
8426
  var this_2 = this;
@@ -23748,7 +23824,7 @@ var lodash_1 = __webpack_require__(96486);
23748
23824
  var BringgException_1 = __webpack_require__(43605);
23749
23825
  var Logger_1 = __importDefault(__webpack_require__(55860));
23750
23826
  var abort_1 = __webpack_require__(34179);
23751
- var version = '9.76.3';
23827
+ var version = '9.76.4-pre';
23752
23828
  function logErrorResponse(response) {
23753
23829
  var data = response.data, status = response.status;
23754
23830
  try {
@@ -26548,6 +26624,42 @@ exports.taskMerger = { mergeTaskIntoExisting: mergeTaskIntoExisting };
26548
26624
 
26549
26625
  "use strict";
26550
26626
 
26627
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26628
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
26629
+ return new (P || (P = Promise))(function (resolve, reject) {
26630
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
26631
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26632
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
26633
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
26634
+ });
26635
+ };
26636
+ var __generator = (this && this.__generator) || function (thisArg, body) {
26637
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
26638
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
26639
+ function verb(n) { return function (v) { return step([n, v]); }; }
26640
+ function step(op) {
26641
+ if (f) throw new TypeError("Generator is already executing.");
26642
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
26643
+ 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;
26644
+ if (y = 0, t) op = [op[0] & 2, t.value];
26645
+ switch (op[0]) {
26646
+ case 0: case 1: t = op; break;
26647
+ case 4: _.label++; return { value: op[1], done: false };
26648
+ case 5: _.label++; y = op[1]; op = [0]; continue;
26649
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
26650
+ default:
26651
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26652
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
26653
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
26654
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
26655
+ if (t[2]) _.ops.pop();
26656
+ _.trys.pop(); continue;
26657
+ }
26658
+ op = body.call(thisArg, _);
26659
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
26660
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
26661
+ }
26662
+ };
26551
26663
  var __values = (this && this.__values) || function(o) {
26552
26664
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
26553
26665
  if (m) return m.call(o);
@@ -26563,11 +26675,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26563
26675
  return (mod && mod.__esModule) ? mod : { "default": mod };
26564
26676
  };
26565
26677
  Object.defineProperty(exports, "__esModule", ({ value: true }));
26678
+ var cloneDeep_1 = __importDefault(__webpack_require__(50361));
26566
26679
  var storable_realtime_subscriptions_1 = __importDefault(__webpack_require__(1227));
26567
26680
  var Tasks_consts_1 = __webpack_require__(24976);
26568
26681
  var TaskRealtimeSubscriptions = /** @class */ (function () {
26569
- function TaskRealtimeSubscriptions(session, tasksStore, storableDataService) {
26682
+ function TaskRealtimeSubscriptions(session, tasksStore, storableDataService, customersApi) {
26570
26683
  this.tasksStore = tasksStore;
26684
+ this.customersApi = customersApi;
26571
26685
  this.storableRealtimeSubscriptions = new storable_realtime_subscriptions_1.default(session, tasksStore, storableDataService);
26572
26686
  }
26573
26687
  TaskRealtimeSubscriptions.prototype.updateStoreOnEvents = function () {
@@ -26618,7 +26732,61 @@ var TaskRealtimeSubscriptions = /** @class */ (function () {
26618
26732
  parentField: 'task_id',
26619
26733
  field: 'way_points',
26620
26734
  ignoreFields: ['way_points'],
26621
- isDelete: false
26735
+ isDelete: false,
26736
+ enrich: {
26737
+ enrichers: [
26738
+ /**
26739
+ * Updating customer on a WayPoint is pretty much an edge case
26740
+ * Customer enrichment can be fully removed if way_point.customer is deprecated and marked as such
26741
+ * that must not be used within dSDK data consumers and all existing usages are removed.
26742
+ * This is what we have to do if we want to avoid unnecessary complications on dSDK side.
26743
+ */
26744
+ {
26745
+ shouldEnrich: function (payload, getTask) {
26746
+ var _a, _b, _c;
26747
+ if (!('customer_id' in payload) || 'customer' in payload) {
26748
+ return false;
26749
+ }
26750
+ 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); });
26751
+ return payload.customer_id !== ((_c = wp === null || wp === void 0 ? void 0 : wp.customer) === null || _c === void 0 ? void 0 : _c.id);
26752
+ },
26753
+ resolveSync: function (payload) {
26754
+ if (payload.customer_id === null) {
26755
+ return { customer: null };
26756
+ }
26757
+ var cached = _this.customersApi.get(payload.customer_id);
26758
+ return cached ? { customer: (0, cloneDeep_1.default)(cached) } : null;
26759
+ },
26760
+ resolveAsync: function (payload, getTask) { return __awaiter(_this, void 0, void 0, function () {
26761
+ var payloadCustomerId, wpId, shouldStop, findWp, customer;
26762
+ return __generator(this, function (_a) {
26763
+ switch (_a.label) {
26764
+ case 0:
26765
+ if (payload.customer_id === null) {
26766
+ return [2 /*return*/, null];
26767
+ }
26768
+ payloadCustomerId = Number(payload.customer_id);
26769
+ wpId = Number(payload.id);
26770
+ shouldStop = function (wp) {
26771
+ return !wp || Number(wp.customer_id) !== payloadCustomerId;
26772
+ };
26773
+ 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; }); };
26774
+ if (shouldStop(findWp())) {
26775
+ return [2 /*return*/, null];
26776
+ }
26777
+ return [4 /*yield*/, this.customersApi.load(payload.customer_id)];
26778
+ case 1:
26779
+ customer = _a.sent();
26780
+ if (shouldStop(findWp())) {
26781
+ return [2 /*return*/, null];
26782
+ }
26783
+ return [2 /*return*/, { customer: (0, cloneDeep_1.default)(customer) }];
26784
+ }
26785
+ });
26786
+ }); }
26787
+ }
26788
+ ]
26789
+ }
26622
26790
  },
26623
26791
  {
26624
26792
  name: Tasks_consts_1.TaskRealTimeEvents.WAYPOINT_DELETED,
@@ -26779,7 +26947,7 @@ var tasks_service_1 = __importDefault(__webpack_require__(8159));
26779
26947
  // hard coded fields to take advantage of the light data store cache
26780
26948
  var READY_TO_EXECUTE_FIELDS = ['ready_to_execute'];
26781
26949
  var TasksApi = /** @class */ (function () {
26782
- function TasksApi(session) {
26950
+ function TasksApi(session, customersApi) {
26783
26951
  var _this = this;
26784
26952
  var groupFilters = [
26785
26953
  {
@@ -26820,7 +26988,7 @@ var TasksApi = /** @class */ (function () {
26820
26988
  params: params
26821
26989
  });
26822
26990
  }, [lightDataStore]);
26823
- this.taskRealtimeSubscriptions = new task_realtime_subscriptions_1.default(session, this.tasksStore, this.storableDataService);
26991
+ this.taskRealtimeSubscriptions = new task_realtime_subscriptions_1.default(session, this.tasksStore, this.storableDataService, customersApi);
26824
26992
  }
26825
26993
  TasksApi.prototype.updateStoreOnEvents = function () {
26826
26994
  this.taskRealtimeSubscriptions.updateStoreOnEvents();