@bringg/dashboard-sdk 10.2.0 → 10.2.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.
@@ -3535,19 +3535,18 @@ var BringgDashboardSDK = /** @class */ (function () {
3535
3535
  exports.BringgDashboardSDK = BringgDashboardSDK;
3536
3536
  function init(session) {
3537
3537
  return __awaiter(this, void 0, void 0, function () {
3538
- var bringg, customersApi, workflows, taskRejectReasons, checkinDistanceReasons;
3538
+ var bringg, workflows, taskRejectReasons, checkinDistanceReasons;
3539
3539
  return __generator(this, function (_a) {
3540
3540
  switch (_a.label) {
3541
3541
  case 0:
3542
3542
  bringg = new BringgDashboardSDK(session);
3543
- customersApi = new customers_api_1.default(session);
3544
3543
  bringg.v2 = {
3545
3544
  vehicles: new vehicles_api_1.default(session),
3546
3545
  relay: new RelayApi_1.default(session),
3547
- tasks: new tasks_api_1.default(session, customersApi),
3546
+ tasks: new tasks_api_1.default(session),
3548
3547
  users: new users_api_1.default(session),
3549
3548
  tags: new tags_api_1.default(session),
3550
- customers: customersApi,
3549
+ customers: new customers_api_1.default(session),
3551
3550
  plannedDeliveryWindows: new planned_delivery_windows_api_1.default(session),
3552
3551
  optimizationResultApi: new optimization_result_api_1.default(session),
3553
3552
  exclusionWindow: new exclusion_window_api_1.ExclusionWindowApi(session),
@@ -9270,17 +9269,6 @@ exports.objectMerger = { deepMerge: deepMerge };
9270
9269
 
9271
9270
  "use strict";
9272
9271
 
9273
- var __assign = (this && this.__assign) || function () {
9274
- __assign = Object.assign || function(t) {
9275
- for (var s, i = 1, n = arguments.length; i < n; i++) {
9276
- s = arguments[i];
9277
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
9278
- t[p] = s[p];
9279
- }
9280
- return t;
9281
- };
9282
- return __assign.apply(this, arguments);
9283
- };
9284
9272
  var __values = (this && this.__values) || function(o) {
9285
9273
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
9286
9274
  if (m) return m.call(o);
@@ -9359,75 +9347,11 @@ var StorableRealtimeSubscriptions = /** @class */ (function () {
9359
9347
  }
9360
9348
  var _loop_2 = function (subEntityEvent) {
9361
9349
  this_2.realtimeSubscriptions.subscribe(subEntityEvent.name, function (subEntityEventData) {
9362
- var e_3, _a;
9363
- var _b, _c;
9364
9350
  subEntityEvent.ignoreFields.forEach(function (field) { return delete subEntityEventData[field]; });
9365
- var parentId = subEntityEventData[subEntityEvent.parentField];
9366
- var entityId = subEntityEventData[subEntityEvent.idField || 'id'];
9367
- var getParent = function () { return _this.dataStore.get(parentId); };
9368
- var pendingEnrichers = [];
9369
- if (subEntityEvent.enrich) {
9370
- var activeEnrichers = subEntityEvent.enrich.enrichers.filter(function (e) {
9371
- return e.shouldEnrich(subEntityEventData, getParent);
9372
- });
9373
- try {
9374
- 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()) {
9375
- var enricher = activeEnrichers_1_1.value;
9376
- var result = (_c = (_b = enricher.resolveSync) === null || _b === void 0 ? void 0 : _b.call(enricher, subEntityEventData, getParent)) !== null && _c !== void 0 ? _c : null;
9377
- if (result !== null) {
9378
- Object.assign(subEntityEventData, result);
9379
- }
9380
- else {
9381
- pendingEnrichers.push(enricher);
9382
- }
9383
- }
9384
- }
9385
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
9386
- finally {
9387
- try {
9388
- if (activeEnrichers_1_1 && !activeEnrichers_1_1.done && (_a = activeEnrichers_1.return)) _a.call(activeEnrichers_1);
9389
- }
9390
- finally { if (e_3) throw e_3.error; }
9391
- }
9392
- }
9393
9351
  var eventChangeData = _this.changeSubEntity(subEntityEventData, subEntityEvent.idField || 'id', subEntityEvent.parentField, subEntityEvent.field, subEntityEvent.isDelete);
9394
9352
  if (eventChangeData === null || eventChangeData === void 0 ? void 0 : eventChangeData.current) {
9395
9353
  _this.runEventCallbacks(subEntityEvent.eventToRaise, eventChangeData);
9396
9354
  }
9397
- if (pendingEnrichers.length > 0) {
9398
- var applyEnrichment_1 = function (data) {
9399
- var _a;
9400
- var _b;
9401
- var parent = _this.dataStore.get(parentId);
9402
- if (!parent) {
9403
- return;
9404
- }
9405
- var subEntity = (_b = parent[subEntityEvent.field]) === null || _b === void 0 ? void 0 : _b.find(function (e) { return Number(e.id) === Number(entityId); });
9406
- if (!subEntity) {
9407
- return;
9408
- }
9409
- var oldValues = Object.fromEntries(Object.keys(data).map(function (key) { return [key, subEntity[key]]; }));
9410
- Object.assign(subEntity, data);
9411
- _this.runEventCallbacks(subEntityEvent.eventToRaise, {
9412
- current: parent,
9413
- diff: (_a = {}, _a[subEntityEvent.field] = [__assign({ id: entityId }, oldValues)], _a)
9414
- });
9415
- };
9416
- // Promise.all is fine here because today there is only one async enricher per event.
9417
- // If multiple async enrichers are ever added, switch to Promise.allSettled so a
9418
- // single rejection does not suppress the results of the others.
9419
- Promise.all(pendingEnrichers.map(function (e) { return e.resolveAsync(subEntityEventData, getParent); }))
9420
- .then(function (results) {
9421
- var asyncData = results.reduce(function (acc, result) { return (result !== null ? Object.assign(acc, result) : acc); }, {});
9422
- if (Object.keys(asyncData).length > 0) {
9423
- applyEnrichment_1(asyncData);
9424
- }
9425
- })
9426
- .catch(function (err) {
9427
- console.error('async enrichment failed for', subEntityEvent.field, 'id', entityId);
9428
- console.error(err);
9429
- });
9430
- }
9431
9355
  });
9432
9356
  };
9433
9357
  var this_2 = this;
@@ -25307,7 +25231,7 @@ var BringgException_1 = __webpack_require__(43605);
25307
25231
  var client_page_1 = __webpack_require__(16573);
25308
25232
  var Logger_1 = __importDefault(__webpack_require__(55860));
25309
25233
  var abort_1 = __webpack_require__(34179);
25310
- var version = '10.2.0';
25234
+ var version = '10.2.1';
25311
25235
  function logErrorResponse(response) {
25312
25236
  var data = response.data, status = response.status;
25313
25237
  try {
@@ -27873,7 +27797,7 @@ var __values = (this && this.__values) || function(o) {
27873
27797
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
27874
27798
  };
27875
27799
  Object.defineProperty(exports, "__esModule", ({ value: true }));
27876
- exports.taskDefaultFields = exports.Routes = exports.baseRoute = exports.TaskRealTimeEvents = exports.DISABLE_WAYPOINT_CUSTOMER_ENRICHMENT_FEATURE_FLAG = exports.answersExtractor = exports.quotesExtractor = exports.formExtractor = exports.taskIdsExtractor = exports.scanCodeExtractor = exports.locationExtractor = exports.childTasksExtractor = exports.tasksExtractor = exports.successExtractor = exports.taskExtractor = exports.defaultExtractor = exports.noteTypes = exports.taskToGroupMapper = exports.groupFilter = exports.TaskGroupTypes = exports.GROUP_VALUES = void 0;
27800
+ exports.taskDefaultFields = exports.Routes = exports.baseRoute = exports.TaskRealTimeEvents = exports.answersExtractor = exports.quotesExtractor = exports.formExtractor = exports.taskIdsExtractor = exports.scanCodeExtractor = exports.locationExtractor = exports.childTasksExtractor = exports.tasksExtractor = exports.successExtractor = exports.taskExtractor = exports.defaultExtractor = exports.noteTypes = exports.taskToGroupMapper = exports.groupFilter = exports.TaskGroupTypes = exports.GROUP_VALUES = void 0;
27877
27801
  var TaskHelpers_1 = __webpack_require__(73119);
27878
27802
  var GROUP_VALUES;
27879
27803
  (function (GROUP_VALUES) {
@@ -27946,8 +27870,6 @@ var quotesExtractor = function (response) { return response.quotes; };
27946
27870
  exports.quotesExtractor = quotesExtractor;
27947
27871
  var answersExtractor = function (response) { return response.answers; };
27948
27872
  exports.answersExtractor = answersExtractor;
27949
- // Turning this on re-exposes the stale way_point.customer it was introduced to fix.
27950
- exports.DISABLE_WAYPOINT_CUSTOMER_ENRICHMENT_FEATURE_FLAG = 'disable_waypoint_customer_enrichment';
27951
27873
  var TaskRealTimeEvents;
27952
27874
  (function (TaskRealTimeEvents) {
27953
27875
  TaskRealTimeEvents["TASK_UPDATE"] = "task update";
@@ -28076,42 +27998,6 @@ exports.taskMerger = { mergeTaskIntoExisting: mergeTaskIntoExisting };
28076
27998
 
28077
27999
  "use strict";
28078
28000
 
28079
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
28080
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28081
- return new (P || (P = Promise))(function (resolve, reject) {
28082
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
28083
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
28084
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
28085
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28086
- });
28087
- };
28088
- var __generator = (this && this.__generator) || function (thisArg, body) {
28089
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28090
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28091
- function verb(n) { return function (v) { return step([n, v]); }; }
28092
- function step(op) {
28093
- if (f) throw new TypeError("Generator is already executing.");
28094
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
28095
- 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;
28096
- if (y = 0, t) op = [op[0] & 2, t.value];
28097
- switch (op[0]) {
28098
- case 0: case 1: t = op; break;
28099
- case 4: _.label++; return { value: op[1], done: false };
28100
- case 5: _.label++; y = op[1]; op = [0]; continue;
28101
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
28102
- default:
28103
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
28104
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28105
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28106
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
28107
- if (t[2]) _.ops.pop();
28108
- _.trys.pop(); continue;
28109
- }
28110
- op = body.call(thisArg, _);
28111
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
28112
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
28113
- }
28114
- };
28115
28001
  var __values = (this && this.__values) || function(o) {
28116
28002
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
28117
28003
  if (m) return m.call(o);
@@ -28127,15 +28013,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28127
28013
  return (mod && mod.__esModule) ? mod : { "default": mod };
28128
28014
  };
28129
28015
  Object.defineProperty(exports, "__esModule", ({ value: true }));
28130
- var cloneDeep_1 = __importDefault(__webpack_require__(50361));
28131
28016
  var storable_realtime_subscriptions_1 = __importDefault(__webpack_require__(1227));
28132
28017
  var vrp_auto_dispatch_status_entity_1 = __importDefault(__webpack_require__(75896));
28133
28018
  var Tasks_consts_1 = __webpack_require__(24976);
28134
28019
  var TaskRealtimeSubscriptions = /** @class */ (function () {
28135
- function TaskRealtimeSubscriptions(session, tasksStore, storableDataService, customersApi) {
28136
- this.session = session;
28020
+ function TaskRealtimeSubscriptions(session, tasksStore, storableDataService) {
28137
28021
  this.tasksStore = tasksStore;
28138
- this.customersApi = customersApi;
28139
28022
  this.storableRealtimeSubscriptions = new storable_realtime_subscriptions_1.default(session, tasksStore, storableDataService);
28140
28023
  this.vrpAutoDispatchStatusEntity = new vrp_auto_dispatch_status_entity_1.default(tasksStore, this.storableRealtimeSubscriptions);
28141
28024
  }
@@ -28181,70 +28064,14 @@ var TaskRealtimeSubscriptions = /** @class */ (function () {
28181
28064
  ignoreFields: ['way_points'],
28182
28065
  isDelete: false
28183
28066
  },
28067
+ // way_point.customer is not refreshed when customer_id changes: resolve the customer by customer_id.
28184
28068
  {
28185
28069
  name: Tasks_consts_1.TaskRealTimeEvents.WAYPOINT_UPDATED,
28186
28070
  eventToRaise: Tasks_consts_1.TaskRealTimeEvents.TASK_UPDATE,
28187
28071
  parentField: 'task_id',
28188
28072
  field: 'way_points',
28189
28073
  ignoreFields: ['way_points'],
28190
- isDelete: false,
28191
- enrich: {
28192
- enrichers: [
28193
- /**
28194
- * Updating customer on a WayPoint is pretty much an edge case
28195
- * Customer enrichment can be fully removed if way_point.customer is deprecated and marked as such
28196
- * that must not be used within dSDK data consumers and all existing usages are removed.
28197
- * This is what we have to do if we want to avoid unnecessary complications on dSDK side.
28198
- */
28199
- {
28200
- shouldEnrich: function (payload, getTask) {
28201
- var _a, _b, _c;
28202
- if (_this.isWaypointCustomerEnrichmentDisabled()) {
28203
- return false;
28204
- }
28205
- if (!('customer_id' in payload) || 'customer' in payload) {
28206
- return false;
28207
- }
28208
- 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); });
28209
- return payload.customer_id !== ((_c = wp === null || wp === void 0 ? void 0 : wp.customer) === null || _c === void 0 ? void 0 : _c.id);
28210
- },
28211
- resolveSync: function (payload) {
28212
- if (payload.customer_id === null) {
28213
- return { customer: null };
28214
- }
28215
- var cached = _this.customersApi.get(payload.customer_id);
28216
- return cached ? { customer: (0, cloneDeep_1.default)(cached) } : null;
28217
- },
28218
- resolveAsync: function (payload, getTask) { return __awaiter(_this, void 0, void 0, function () {
28219
- var payloadCustomerId, wpId, shouldStop, findWp, customer;
28220
- return __generator(this, function (_a) {
28221
- switch (_a.label) {
28222
- case 0:
28223
- if (payload.customer_id === null) {
28224
- return [2 /*return*/, null];
28225
- }
28226
- payloadCustomerId = Number(payload.customer_id);
28227
- wpId = Number(payload.id);
28228
- shouldStop = function (wp) {
28229
- return !wp || Number(wp.customer_id) !== payloadCustomerId;
28230
- };
28231
- 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; }); };
28232
- if (shouldStop(findWp())) {
28233
- return [2 /*return*/, null];
28234
- }
28235
- return [4 /*yield*/, this.customersApi.load(payload.customer_id)];
28236
- case 1:
28237
- customer = _a.sent();
28238
- if (shouldStop(findWp())) {
28239
- return [2 /*return*/, null];
28240
- }
28241
- return [2 /*return*/, { customer: (0, cloneDeep_1.default)(customer) }];
28242
- }
28243
- });
28244
- }); }
28245
- }
28246
- ]
28247
- }
28074
+ isDelete: false
28248
28075
  },
28249
28076
  {
28250
28077
  name: Tasks_consts_1.TaskRealTimeEvents.WAYPOINT_DELETED,
@@ -28296,11 +28123,6 @@ var TaskRealtimeSubscriptions = /** @class */ (function () {
28296
28123
  finally { if (e_1) throw e_1.error; }
28297
28124
  }
28298
28125
  };
28299
- TaskRealtimeSubscriptions.prototype.isWaypointCustomerEnrichmentDisabled = function () {
28300
- var _a;
28301
- var featureFlags = (((_a = this.session.merchant) === null || _a === void 0 ? void 0 : _a.feature_flags) || {});
28302
- return Boolean(featureFlags[Tasks_consts_1.DISABLE_WAYPOINT_CUSTOMER_ENRICHMENT_FEATURE_FLAG]);
28303
- };
28304
28126
  return TaskRealtimeSubscriptions;
28305
28127
  }());
28306
28128
  exports["default"] = TaskRealtimeSubscriptions;
@@ -28413,7 +28235,7 @@ var tasks_service_1 = __importDefault(__webpack_require__(8159));
28413
28235
  // hard coded fields to take advantage of the light data store cache
28414
28236
  var READY_TO_EXECUTE_FIELDS = ['ready_to_execute'];
28415
28237
  var TasksApi = /** @class */ (function () {
28416
- function TasksApi(session, customersApi) {
28238
+ function TasksApi(session) {
28417
28239
  var _this = this;
28418
28240
  var groupFilters = [
28419
28241
  {
@@ -28454,7 +28276,7 @@ var TasksApi = /** @class */ (function () {
28454
28276
  params: params
28455
28277
  });
28456
28278
  }, [lightDataStore]);
28457
- this.taskRealtimeSubscriptions = new task_realtime_subscriptions_1.default(session, this.tasksStore, this.storableDataService, customersApi);
28279
+ this.taskRealtimeSubscriptions = new task_realtime_subscriptions_1.default(session, this.tasksStore, this.storableDataService);
28458
28280
  }
28459
28281
  TasksApi.prototype.updateStoreOnEvents = function () {
28460
28282
  this.taskRealtimeSubscriptions.updateStoreOnEvents();