@bringg/dashboard-sdk 9.8.7 → 9.8.9-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.
@@ -2601,6 +2601,7 @@ var AsyncOperationStatus_1 = __webpack_require__(37360);
2601
2601
  var BillingApi_1 = __importDefault(__webpack_require__(25475));
2602
2602
  var Chat_1 = __importDefault(__webpack_require__(17629));
2603
2603
  var ChatConversationApi_1 = __importDefault(__webpack_require__(74617));
2604
+ var collapse_linked_tasks_api_1 = __importDefault(__webpack_require__(1610));
2604
2605
  var Company_1 = __importDefault(__webpack_require__(97275));
2605
2606
  var ConfigurationProvider_1 = __webpack_require__(44858);
2606
2607
  var Crew_1 = __importDefault(__webpack_require__(83916));
@@ -2930,20 +2931,22 @@ var BringgDashboardSDK = /** @class */ (function () {
2930
2931
  exports.BringgDashboardSDK = BringgDashboardSDK;
2931
2932
  function init(session) {
2932
2933
  return __awaiter(this, void 0, void 0, function () {
2933
- var bringg, workflows, taskRejectReasons, presetViews;
2934
+ var bringg, workflows, taskRejectReasons, presetViews, tasksApi;
2934
2935
  return __generator(this, function (_a) {
2935
2936
  switch (_a.label) {
2936
2937
  case 0:
2937
2938
  bringg = new BringgDashboardSDK(session);
2939
+ tasksApi = new tasks_api_1.default(session);
2938
2940
  bringg.v2 = {
2939
2941
  vehicles: new vehicles_api_1.default(session),
2940
- tasks: new tasks_api_1.default(session),
2942
+ tasks: tasksApi,
2941
2943
  customers: new customers_api_1.default(session),
2942
2944
  plannedDeliveryWindows: new planned_delivery_windows_api_1.default(session),
2943
2945
  optimizationResultApi: new optimization_result_api_1.default(session),
2944
2946
  exclusionWindow: new exclusion_window_api_1.ExclusionWindowApi(session),
2945
2947
  serviceAreas: new service_area_api_1.ServiceAreaApi(session),
2946
2948
  lookup: new lookup_api_1.default(session),
2949
+ collapseLinkedTasks: new collapse_linked_tasks_api_1.default(tasksApi),
2947
2950
  createWorkflows: function (mapper) {
2948
2951
  workflows = new workflows_api_1.default(session, mapper);
2949
2952
  return workflows;
@@ -3886,6 +3889,257 @@ exports["default"] = ChatMessage;
3886
3889
 
3887
3890
  /***/ }),
3888
3891
 
3892
+ /***/ 1610:
3893
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
3894
+
3895
+ "use strict";
3896
+
3897
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3898
+ return (mod && mod.__esModule) ? mod : { "default": mod };
3899
+ };
3900
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
3901
+ var lodash_1 = __webpack_require__(96486);
3902
+ var collapse_linked_tasks_service_1 = __importDefault(__webpack_require__(26172));
3903
+ var CollapseLinkedTasksApi = /** @class */ (function () {
3904
+ function CollapseLinkedTasksApi(tasksApi) {
3905
+ var _this = this;
3906
+ this.sortTasksByPriority = function (tasks) {
3907
+ return tasks.sort(function (a, b) {
3908
+ if (a.priority < b.priority) {
3909
+ return -1;
3910
+ }
3911
+ else if (a.priority > b.priority) {
3912
+ return 1;
3913
+ }
3914
+ return 0;
3915
+ });
3916
+ };
3917
+ this.buildPlanningTasks = function (tasks) {
3918
+ var buildTasks = _this.collapseLinkedTasksService.buildTasks(_this.sortTasksByPriority(tasks));
3919
+ buildTasks.forEach(function (task) {
3920
+ _this.planningTasks.set(task.id, task);
3921
+ });
3922
+ return _this.getPlanningTasks();
3923
+ };
3924
+ this.buildDispatchTasks = function (tasks) {
3925
+ var buildTasks = _this.collapseLinkedTasksService.buildTasks(_this.sortTasksByPriority(tasks));
3926
+ buildTasks.forEach(function (task) {
3927
+ _this.dispatchTasks.set(task.id, task);
3928
+ });
3929
+ return _this.getDispatchTasks();
3930
+ };
3931
+ this.getPlanningTasks = function () {
3932
+ return Array.from(_this.planningTasks.values());
3933
+ };
3934
+ this.getDispatchTasks = function () {
3935
+ return Array.from(_this.dispatchTasks.values());
3936
+ };
3937
+ this.getCollapseLinkedTasksById = function (id) {
3938
+ return _this.collapseLinkTasksMap.get(id);
3939
+ };
3940
+ this.setTasksByRunId = function (runId, tasks) {
3941
+ _this.taskWithCollapseIdsByRunId.set(runId, tasks);
3942
+ };
3943
+ this.setCollapsedLinkTasks = function (runId, collapseLinkedTasks) {
3944
+ _this.collapseLinkTasksMap.set(collapseLinkedTasks.id, collapseLinkedTasks);
3945
+ };
3946
+ this.getAllTasksAndCollapsedTasks = function () {
3947
+ return (0, lodash_1.flatten)(Array.from(_this.taskWithCollapseIdsByRunId.values()));
3948
+ };
3949
+ this.getTaskWithCollapseByRunId = function (runId) {
3950
+ return _this.taskWithCollapseIdsByRunId.get(runId);
3951
+ };
3952
+ this.tasksApi = tasksApi;
3953
+ this.collapseLinkTasksMap = new Map();
3954
+ this.taskWithCollapseIdsByRunId = new Map();
3955
+ this.planningTasks = new Map();
3956
+ this.dispatchTasks = new Map();
3957
+ this.collapseLinkedTasksService = new collapse_linked_tasks_service_1.default({
3958
+ setTasksByRunId: this.setTasksByRunId,
3959
+ setCollapsedLinkTasks: this.setCollapsedLinkTasks,
3960
+ getAllTasksAndCollapsedTasks: this.getAllTasksAndCollapsedTasks,
3961
+ getCollapseLinkedTasksById: this.getCollapseLinkedTasksById,
3962
+ getTaskWithCollapseByRunId: this.getTaskWithCollapseByRunId
3963
+ });
3964
+ this.tasksApi.onCreate(this.onCreate);
3965
+ this.tasksApi.onUpdate(this.onUpdate);
3966
+ this.tasksApi.onDelete(this.onDelete);
3967
+ }
3968
+ CollapseLinkedTasksApi.prototype.onUpdate = function (mappedStorableItem) {
3969
+ // TODO
3970
+ };
3971
+ CollapseLinkedTasksApi.prototype.onCreate = function (mappedStorableItem) {
3972
+ // TODO
3973
+ };
3974
+ CollapseLinkedTasksApi.prototype.onDelete = function (mappedStorableItem) {
3975
+ // TODO
3976
+ };
3977
+ return CollapseLinkedTasksApi;
3978
+ }());
3979
+ exports["default"] = CollapseLinkedTasksApi;
3980
+ //# sourceMappingURL=collapse-linked-tasks-api.js.map
3981
+
3982
+ /***/ }),
3983
+
3984
+ /***/ 26172:
3985
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
3986
+
3987
+ "use strict";
3988
+
3989
+ var __assign = (this && this.__assign) || function () {
3990
+ __assign = Object.assign || function(t) {
3991
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
3992
+ s = arguments[i];
3993
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
3994
+ t[p] = s[p];
3995
+ }
3996
+ return t;
3997
+ };
3998
+ return __assign.apply(this, arguments);
3999
+ };
4000
+ var __read = (this && this.__read) || function (o, n) {
4001
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4002
+ if (!m) return o;
4003
+ var i = m.call(o), r, ar = [], e;
4004
+ try {
4005
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
4006
+ }
4007
+ catch (error) { e = { error: error }; }
4008
+ finally {
4009
+ try {
4010
+ if (r && !r.done && (m = i["return"])) m.call(i);
4011
+ }
4012
+ finally { if (e) throw e.error; }
4013
+ }
4014
+ return ar;
4015
+ };
4016
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
4017
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4018
+ if (ar || !(i in from)) {
4019
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
4020
+ ar[i] = from[i];
4021
+ }
4022
+ }
4023
+ return to.concat(ar || Array.prototype.slice.call(from));
4024
+ };
4025
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
4026
+ var lodash_1 = __webpack_require__(96486);
4027
+ var CollapseLinkedTasksService = /** @class */ (function () {
4028
+ function CollapseLinkedTasksService(props) {
4029
+ var _this = this;
4030
+ this.reOrderAndSaveTaskIds = function (tasks) {
4031
+ var tasksByRunId = (0, lodash_1.groupBy)(tasks, function (task) { return task.run_id; });
4032
+ Object.entries(tasksByRunId).forEach(function (_a) {
4033
+ var _b = __read(_a, 2), key = _b[0], runTasks = _b[1];
4034
+ var runId = Number(key);
4035
+ if (!runId) {
4036
+ return;
4037
+ }
4038
+ var previousTasksWithCollapsedTasks = _this.props.getTaskWithCollapseByRunId(runId) || [];
4039
+ var needToReOrderAgain = previousTasksWithCollapsedTasks.length;
4040
+ var previousTasks = needToReOrderAgain
4041
+ ? _this.extractTasksFromCollapsedTasks(previousTasksWithCollapsedTasks)
4042
+ : [];
4043
+ // TODO check if the getTasksByRunId effect on routes planner, because the data now are not updated by eta/etl etc..
4044
+ var orderedTasks = _this.reOrderTasksByCustomer(__spreadArray(__spreadArray([], __read(previousTasks), false), __read(runTasks), false));
4045
+ _this.saveResult(runId, orderedTasks);
4046
+ });
4047
+ };
4048
+ this.buildTasks = function (tasks) {
4049
+ _this.reOrderAndSaveTaskIds(tasks);
4050
+ return _this.extractReorderedTasks();
4051
+ };
4052
+ this.extractReorderedTasks = function () {
4053
+ var results = [];
4054
+ _this.props.getAllTasksAndCollapsedTasks().forEach(function (task) {
4055
+ if (task.id > 0) {
4056
+ results.push(task);
4057
+ }
4058
+ else {
4059
+ var collapseLinkTasks = _this.props.getCollapseLinkedTasksById(task.id);
4060
+ var firstTask = __assign(__assign({}, collapseLinkTasks.tasks[0]), { id: collapseLinkTasks.id, external_id: 'Pickup Area', title: 'Pickup Area', tasks: collapseLinkTasks.tasks, team_id: collapseLinkTasks.tasks[0].team_ids[0] });
4061
+ results.push(firstTask);
4062
+ }
4063
+ });
4064
+ return Array.from(results.values());
4065
+ };
4066
+ this.extractTasksFromCollapsedTasks = function (tasks) {
4067
+ var extractedTasks = [];
4068
+ tasks.forEach(function (task) {
4069
+ var isCollapsedTask = task.id < 0;
4070
+ if (isCollapsedTask) {
4071
+ var collapsedTask = _this.props.getCollapseLinkedTasksById(task.id);
4072
+ extractedTasks.push.apply(extractedTasks, __spreadArray([], __read(collapsedTask.tasks), false));
4073
+ }
4074
+ else {
4075
+ extractedTasks.push(task);
4076
+ }
4077
+ });
4078
+ return extractedTasks;
4079
+ };
4080
+ this.saveResult = function (runId, tasks) {
4081
+ var collapsedLinkedTasks = tasks.filter(function (task) { return task.id < 0; });
4082
+ collapsedLinkedTasks.forEach(function (collapseLinkTask) {
4083
+ return _this.props.setCollapsedLinkTasks(runId, collapseLinkTask);
4084
+ });
4085
+ _this.props.setTasksByRunId(runId, tasks);
4086
+ };
4087
+ this.getOnlyTaskIds = function (tasks) {
4088
+ var taskIds = [];
4089
+ tasks.forEach(function (task) {
4090
+ if (task.id < 0) {
4091
+ taskIds.push(task.tasks);
4092
+ }
4093
+ else {
4094
+ taskIds.push(task.id);
4095
+ }
4096
+ });
4097
+ return taskIds;
4098
+ };
4099
+ this.getCustomerId = function (task) {
4100
+ return (0, lodash_1.last)(task.way_points).customer_id;
4101
+ };
4102
+ this.reOrderTasksByCustomer = function (runTasks) {
4103
+ if (!runTasks.length) {
4104
+ return [];
4105
+ }
4106
+ var firstTask = runTasks[0];
4107
+ var lastCustomerId = _this.getCustomerId(firstTask);
4108
+ var newTasksOrder = [firstTask];
4109
+ runTasks.slice(1).forEach(function (task) {
4110
+ var currentCustomerId = _this.getCustomerId(task);
4111
+ if (lastCustomerId === currentCustomerId) {
4112
+ var lastTaskIsCollapsedTask = Array.isArray(newTasksOrder[newTasksOrder.length - 1].tasks);
4113
+ if (lastTaskIsCollapsedTask) {
4114
+ newTasksOrder[newTasksOrder.length - 1].tasks.push(task);
4115
+ }
4116
+ else {
4117
+ var lastTask = newTasksOrder.pop();
4118
+ var collapseLinkTasks = {
4119
+ id: lastTask.id * -1,
4120
+ customer_id: currentCustomerId,
4121
+ tasks: [lastTask, task],
4122
+ runId: lastTask.run_id
4123
+ };
4124
+ newTasksOrder.push(collapseLinkTasks);
4125
+ }
4126
+ }
4127
+ else {
4128
+ lastCustomerId = currentCustomerId;
4129
+ newTasksOrder.push(task);
4130
+ }
4131
+ });
4132
+ return newTasksOrder;
4133
+ };
4134
+ this.props = props;
4135
+ }
4136
+ return CollapseLinkedTasksService;
4137
+ }());
4138
+ exports["default"] = CollapseLinkedTasksService;
4139
+ //# sourceMappingURL=collapse-linked-tasks-service.js.map
4140
+
4141
+ /***/ }),
4142
+
3889
4143
  /***/ 97275:
3890
4144
  /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
3891
4145
 
@@ -22256,7 +22510,7 @@ var lodash_1 = __webpack_require__(96486);
22256
22510
  var BringgException_1 = __webpack_require__(43605);
22257
22511
  var Logger_1 = __importDefault(__webpack_require__(55860));
22258
22512
  var abort_1 = __webpack_require__(34179);
22259
- var version = '9.8.7';
22513
+ var version = '9.8.9-pre';
22260
22514
  function logErrorResponse(response) {
22261
22515
  var data = response.data, status = response.status;
22262
22516
  try {
@@ -25518,7 +25772,7 @@ var TasksService = /** @class */ (function () {
25518
25772
  TasksService.prototype.finish = function (id, commonOptions) {
25519
25773
  return this.service.routeGenerator
25520
25774
  .post(Tasks_consts_1.Routes.FINISH_TASK)
25521
- .withExtractor(Tasks_consts_1.defaultExtractor)
25775
+ .withExtractor(Tasks_consts_1.taskExtractor)
25522
25776
  .setException("failed to finish task - ".concat(id))
25523
25777
  .withRouteParams({ id: id })
25524
25778
  .withCommonOptions(commonOptions)