b2m-utils 0.0.113 → 0.0.115

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.
package/build/index.js CHANGED
@@ -2,259 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var formatDateString = function (dateString, staticTime) {
6
- if (staticTime === void 0) { staticTime = false; }
7
- if (dateString.includes('.000Z')) {
8
- var firstSplit = dateString === null || dateString === void 0 ? void 0 : dateString.split('.000Z')[0];
9
- var secondSplit = firstSplit === null || firstSplit === void 0 ? void 0 : firstSplit.split('T');
10
- if (secondSplit === null || secondSplit === void 0 ? void 0 : secondSplit.length) {
11
- if (staticTime) {
12
- return "".concat(secondSplit[0], " 12:00:00");
13
- }
14
- else {
15
- return "".concat(secondSplit[0], " ").concat(secondSplit[1]);
16
- }
17
- }
18
- }
19
- else if (dateString.includes(' ')) {
20
- if (staticTime) {
21
- return "".concat(dateString.split(' ')[0], " 12:00:00");
22
- }
23
- else {
24
- return dateString;
25
- }
26
- }
27
- return '';
28
- };
29
-
30
- function getConfigurationFromDomain(domainConfigurations, configurationName) {
31
- return domainConfigurations.find(function (i) { return i.name === configurationName; });
32
- }
33
-
34
- var getCookies = function (cookies) {
35
- if (cookies) {
36
- var data_1 = {};
37
- cookies
38
- .split(';')
39
- .map(function (item) { return item.trim().split('='); })
40
- .forEach(function (item) { return (data_1[item[0]] = item[1]); });
41
- return data_1;
42
- }
43
- else {
44
- return {};
45
- }
46
- };
47
-
48
- function getDataFromToken(token) {
49
- var jwtDataBase64 = token.split('.')[1];
50
- var data = JSON.parse(Buffer.from(jwtDataBase64, 'base64').toString());
51
- if (data.exp * 1000 < Date.now()) {
52
- throw new Error('Token expirado.');
53
- }
54
- return data;
55
- }
56
-
57
- exports.ApplicationColumnNameEnum = void 0;
58
- (function (ApplicationColumnNameEnum) {
59
- ApplicationColumnNameEnum["DEPARTURE_AT"] = "departureAt";
60
- ApplicationColumnNameEnum["ARRIVAL_AT"] = "arrivalAt";
61
- ApplicationColumnNameEnum["CLEARANCE_AT"] = "clearanceAt";
62
- ApplicationColumnNameEnum["DELIVERY_AT"] = "deliveryAt";
63
- ApplicationColumnNameEnum["CREATED_AT"] = "createdAt";
64
- })(exports.ApplicationColumnNameEnum || (exports.ApplicationColumnNameEnum = {}));
65
-
66
- exports.ApplicationEnum = void 0;
67
- (function (ApplicationEnum) {
68
- ApplicationEnum[ApplicationEnum["B2M_CORE"] = 1] = "B2M_CORE";
69
- ApplicationEnum[ApplicationEnum["TMS"] = 2] = "TMS";
70
- ApplicationEnum[ApplicationEnum["SPOT"] = 3] = "SPOT";
71
- ApplicationEnum[ApplicationEnum["TRACK_PROCESSES"] = 4] = "TRACK_PROCESSES";
72
- ApplicationEnum[ApplicationEnum["RATECARD_MANAGEMENT"] = 5] = "RATECARD_MANAGEMENT";
73
- ApplicationEnum[ApplicationEnum["SLA"] = 6] = "SLA";
74
- ApplicationEnum[ApplicationEnum["AUDIT"] = 7] = "AUDIT";
75
- })(exports.ApplicationEnum || (exports.ApplicationEnum = {}));
76
-
77
- exports.CountryEnum = void 0;
78
- (function (CountryEnum) {
79
- CountryEnum[CountryEnum["BRAZIL"] = 1] = "BRAZIL";
80
- })(exports.CountryEnum || (exports.CountryEnum = {}));
81
-
82
- exports.CurrencyEnum = void 0;
83
- (function (CurrencyEnum) {
84
- CurrencyEnum[CurrencyEnum["REAL"] = 1] = "REAL";
85
- CurrencyEnum[CurrencyEnum["DOLAR"] = 2] = "DOLAR";
86
- CurrencyEnum[CurrencyEnum["EURO"] = 3] = "EURO";
87
- CurrencyEnum[CurrencyEnum["IENE"] = 4] = "IENE";
88
- })(exports.CurrencyEnum || (exports.CurrencyEnum = {}));
89
-
90
- exports.DomainConfigurationEnum = void 0;
91
- (function (DomainConfigurationEnum) {
92
- DomainConfigurationEnum["CLEARANCE_DAYS"] = "CLEARANCE_DAYS";
93
- DomainConfigurationEnum["CARGO_REMOVAL_DAYS"] = "CARGO_REMOVAL_DAYS";
94
- DomainConfigurationEnum["DELIVERY_DAYS"] = "DELIVERY_DAYS";
95
- DomainConfigurationEnum["DEMURRAGE_EXPIRY_NOTIFICATION_DAYS"] = "DEMURRAGE_EXPIRY_NOTIFICATION_DAYS";
96
- DomainConfigurationEnum["INVOICE_EXPIRY_NOTIFICATION_DAYS"] = "INVOICE_EXPIRY_NOTIFICATION_DAYS";
97
- })(exports.DomainConfigurationEnum || (exports.DomainConfigurationEnum = {}));
98
-
99
- exports.DomainTypeEnum = void 0;
100
- (function (DomainTypeEnum) {
101
- DomainTypeEnum[DomainTypeEnum["TMS"] = 1] = "TMS";
102
- DomainTypeEnum[DomainTypeEnum["SPOT"] = 2] = "SPOT";
103
- DomainTypeEnum[DomainTypeEnum["PROVIDER"] = 3] = "PROVIDER";
104
- DomainTypeEnum[DomainTypeEnum["FREIGHT_FORWARDER"] = 4] = "FREIGHT_FORWARDER";
105
- DomainTypeEnum[DomainTypeEnum["DISPATCHER"] = 5] = "DISPATCHER";
106
- DomainTypeEnum[DomainTypeEnum["B2M_CLIENT"] = 6] = "B2M_CLIENT";
107
- })(exports.DomainTypeEnum || (exports.DomainTypeEnum = {}));
108
-
109
- exports.FeeCalculationTypeEnum = void 0;
110
- (function (FeeCalculationTypeEnum) {
111
- FeeCalculationTypeEnum[FeeCalculationTypeEnum["FIXED"] = 1] = "FIXED";
112
- FeeCalculationTypeEnum[FeeCalculationTypeEnum["TAXED_WEIGHT"] = 2] = "TAXED_WEIGHT";
113
- FeeCalculationTypeEnum[FeeCalculationTypeEnum["INTERNATIONAL_CHARGE"] = 3] = "INTERNATIONAL_CHARGE";
114
- FeeCalculationTypeEnum[FeeCalculationTypeEnum["CONVERSION_TAX"] = 4] = "CONVERSION_TAX";
115
- FeeCalculationTypeEnum[FeeCalculationTypeEnum["CUBED_WEIGHT"] = 5] = "CUBED_WEIGHT";
116
- FeeCalculationTypeEnum[FeeCalculationTypeEnum["COMMODITY_VALUE"] = 6] = "COMMODITY_VALUE";
117
- FeeCalculationTypeEnum[FeeCalculationTypeEnum["FRACTIONED"] = 7] = "FRACTIONED";
118
- FeeCalculationTypeEnum[FeeCalculationTypeEnum["FREIGHT"] = 8] = "FREIGHT";
119
- FeeCalculationTypeEnum[FeeCalculationTypeEnum["TOTAL_PERCENTAGE"] = 9] = "TOTAL_PERCENTAGE";
120
- FeeCalculationTypeEnum[FeeCalculationTypeEnum["MIN_VALUE"] = 10] = "MIN_VALUE";
121
- FeeCalculationTypeEnum[FeeCalculationTypeEnum["SUM_CONTAINERS"] = 11] = "SUM_CONTAINERS";
122
- })(exports.FeeCalculationTypeEnum || (exports.FeeCalculationTypeEnum = {}));
123
-
124
- exports.FeeCategoryEnum = void 0;
125
- (function (FeeCategoryEnum) {
126
- FeeCategoryEnum[FeeCategoryEnum["ORIGIN"] = 1] = "ORIGIN";
127
- FeeCategoryEnum[FeeCategoryEnum["INTERNATIONAL"] = 2] = "INTERNATIONAL";
128
- FeeCategoryEnum[FeeCategoryEnum["DESTINATION"] = 3] = "DESTINATION";
129
- FeeCategoryEnum[FeeCategoryEnum["DELIVERY"] = 4] = "DELIVERY";
130
- FeeCategoryEnum[FeeCategoryEnum["ADDITIONAL"] = 5] = "ADDITIONAL";
131
- FeeCategoryEnum[FeeCategoryEnum["PICKUP"] = 6] = "PICKUP";
132
- FeeCategoryEnum[FeeCategoryEnum["FREIGHT"] = 7] = "FREIGHT";
133
- FeeCategoryEnum[FeeCategoryEnum["FEES"] = 8] = "FEES";
134
- FeeCategoryEnum[FeeCategoryEnum["TAXES"] = 9] = "TAXES";
135
- })(exports.FeeCategoryEnum || (exports.FeeCategoryEnum = {}));
136
-
137
- exports.ModalEnum = void 0;
138
- (function (ModalEnum) {
139
- ModalEnum[ModalEnum["AIR"] = 1] = "AIR";
140
- ModalEnum[ModalEnum["OCEAN_FCL"] = 2] = "OCEAN_FCL";
141
- ModalEnum[ModalEnum["OCEAN_LCL"] = 3] = "OCEAN_LCL";
142
- ModalEnum[ModalEnum["ROAD_FTL"] = 4] = "ROAD_FTL";
143
- ModalEnum[ModalEnum["ROAD_LTL"] = 5] = "ROAD_LTL";
144
- })(exports.ModalEnum || (exports.ModalEnum = {}));
145
-
146
- exports.NotificationTypeEnum = void 0;
147
- (function (NotificationTypeEnum) {
148
- NotificationTypeEnum[NotificationTypeEnum["USER_NOTIFICATION"] = 1] = "USER_NOTIFICATION";
149
- NotificationTypeEnum[NotificationTypeEnum["DOMAIN_NOTIFICATION"] = 2] = "DOMAIN_NOTIFICATION";
150
- })(exports.NotificationTypeEnum || (exports.NotificationTypeEnum = {}));
151
-
152
- exports.PermissionEnum = void 0;
153
- (function (PermissionEnum) {
154
- PermissionEnum[PermissionEnum["B2M_ADMIN"] = 1] = "B2M_ADMIN";
155
- PermissionEnum[PermissionEnum["DOMAIN_ADMIN"] = 2] = "DOMAIN_ADMIN";
156
- PermissionEnum[PermissionEnum["TMS"] = 3] = "TMS";
157
- PermissionEnum[PermissionEnum["SPOT"] = 4] = "SPOT";
158
- PermissionEnum[PermissionEnum["SPOT_PROVIDER"] = 5] = "SPOT_PROVIDER";
159
- PermissionEnum[PermissionEnum["TRACK_PROCESSES"] = 6] = "TRACK_PROCESSES";
160
- PermissionEnum[PermissionEnum["DISPATCHER"] = 7] = "DISPATCHER";
161
- PermissionEnum[PermissionEnum["RATECARD_MANAGEMENT"] = 8] = "RATECARD_MANAGEMENT";
162
- PermissionEnum[PermissionEnum["SLA"] = 9] = "SLA";
163
- })(exports.PermissionEnum || (exports.PermissionEnum = {}));
164
-
165
- exports.SpotStatusEnum = void 0;
166
- (function (SpotStatusEnum) {
167
- SpotStatusEnum[SpotStatusEnum["DRAFT"] = 1] = "DRAFT";
168
- SpotStatusEnum[SpotStatusEnum["OPEN"] = 2] = "OPEN";
169
- SpotStatusEnum[SpotStatusEnum["CLOSED"] = 3] = "CLOSED";
170
- SpotStatusEnum[SpotStatusEnum["FINISHED"] = 4] = "FINISHED";
171
- })(exports.SpotStatusEnum || (exports.SpotStatusEnum = {}));
172
-
173
- exports.TrackProcessProviderTypeEnum = void 0;
174
- (function (TrackProcessProviderTypeEnum) {
175
- TrackProcessProviderTypeEnum[TrackProcessProviderTypeEnum["FREIGHT_FORWARDER"] = 1] = "FREIGHT_FORWARDER";
176
- TrackProcessProviderTypeEnum[TrackProcessProviderTypeEnum["DISPATCHER"] = 2] = "DISPATCHER";
177
- TrackProcessProviderTypeEnum[TrackProcessProviderTypeEnum["TERMINAL"] = 3] = "TERMINAL";
178
- TrackProcessProviderTypeEnum[TrackProcessProviderTypeEnum["SHIPPING_COMPANY"] = 4] = "SHIPPING_COMPANY";
179
- TrackProcessProviderTypeEnum[TrackProcessProviderTypeEnum["OTHERS"] = 5] = "OTHERS";
180
- })(exports.TrackProcessProviderTypeEnum || (exports.TrackProcessProviderTypeEnum = {}));
181
-
182
- var getFormattedFreightPlaceName = function (freightPlace, modalId, complete, sqlVersion) {
183
- var _a, _b;
184
- if (complete === void 0) { complete = false; }
185
- if (sqlVersion === void 0) { sqlVersion = false; }
186
- if (sqlVersion) {
187
- var iataText = freightPlace.iata ? "(".concat(freightPlace.iata, ") ") : '';
188
- var locationText = freightPlace.location ? " ".concat(freightPlace.location) : '';
189
- var countryText = [exports.ModalEnum.OCEAN_FCL, exports.ModalEnum.OCEAN_LCL].includes(modalId) ? "".concat(freightPlace.freightPlaceCountryName, ", ") : '';
190
- return "".concat(iataText).concat(freightPlace.name).concat(locationText).concat(complete ? " - ".concat(countryText).concat(freightPlace.freightPlaceRegionName) : '');
191
- }
192
- else {
193
- var iataText = freightPlace.iata ? "(".concat(freightPlace.iata, ") ") : '';
194
- var locationText = freightPlace.location ? " ".concat(freightPlace.location) : '';
195
- var countryText = [exports.ModalEnum.OCEAN_FCL, exports.ModalEnum.OCEAN_LCL].includes(modalId) ? "".concat((_a = freightPlace.freightPlaceCountry) === null || _a === void 0 ? void 0 : _a.name, ", ") : '';
196
- return "".concat(iataText).concat(freightPlace.name).concat(locationText).concat(complete ? " - ".concat(countryText).concat((_b = freightPlace.freightPlaceRegion) === null || _b === void 0 ? void 0 : _b.name) : '');
197
- }
198
- };
199
-
200
- /******************************************************************************
201
- Copyright (c) Microsoft Corporation.
202
-
203
- Permission to use, copy, modify, and/or distribute this software for any
204
- purpose with or without fee is hereby granted.
205
-
206
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
207
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
208
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
209
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
210
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
211
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
212
- PERFORMANCE OF THIS SOFTWARE.
213
- ***************************************************************************** */
214
-
215
- function __awaiter(thisArg, _arguments, P, generator) {
216
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
217
- return new (P || (P = Promise))(function (resolve, reject) {
218
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
219
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
220
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
221
- step((generator = generator.apply(thisArg, _arguments || [])).next());
222
- });
223
- }
224
-
225
- function __generator(thisArg, body) {
226
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
227
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
228
- function verb(n) { return function (v) { return step([n, v]); }; }
229
- function step(op) {
230
- if (f) throw new TypeError("Generator is already executing.");
231
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
232
- 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;
233
- if (y = 0, t) op = [op[0] & 2, t.value];
234
- switch (op[0]) {
235
- case 0: case 1: t = op; break;
236
- case 4: _.label++; return { value: op[1], done: false };
237
- case 5: _.label++; y = op[1]; op = [0]; continue;
238
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
239
- default:
240
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
241
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
242
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
243
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
244
- if (t[2]) _.ops.pop();
245
- _.trys.pop(); continue;
246
- }
247
- op = body.call(thisArg, _);
248
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
249
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
250
- }
251
- }
252
-
253
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
254
- var e = new Error(message);
255
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
256
- };
257
-
258
5
  /**
259
6
  * @name toDate
260
7
  * @category Common Helpers
@@ -6160,6 +5907,355 @@ const ptBR = {
6160
5907
  },
6161
5908
  };
6162
5909
 
5910
+ var formatDateString = function (dateString, staticTime) {
5911
+ if (staticTime === void 0) { staticTime = false; }
5912
+ if (dateString.includes('.000Z')) {
5913
+ var firstSplit = dateString === null || dateString === void 0 ? void 0 : dateString.split('.000Z')[0];
5914
+ var secondSplit = firstSplit === null || firstSplit === void 0 ? void 0 : firstSplit.split('T');
5915
+ if (secondSplit === null || secondSplit === void 0 ? void 0 : secondSplit.length) {
5916
+ if (staticTime) {
5917
+ return "".concat(secondSplit[0], " 12:00:00");
5918
+ }
5919
+ else {
5920
+ return "".concat(secondSplit[0], " ").concat(secondSplit[1]);
5921
+ }
5922
+ }
5923
+ }
5924
+ else if (dateString.includes(' ')) {
5925
+ if (staticTime) {
5926
+ return "".concat(dateString.split(' ')[0], " 12:00:00");
5927
+ }
5928
+ else {
5929
+ return dateString;
5930
+ }
5931
+ }
5932
+ return '';
5933
+ };
5934
+
5935
+ var getContractFromFreight = function (contracts, freight) {
5936
+ return contracts.find(function (item) {
5937
+ if (item.shippingCompanyId === freight.shippingCompanyId) {
5938
+ var formattedCteAt = format(parse(formatDateString(freight.cteAt), "yyyy-MM-dd HH:mm:ss", new Date()), "yyyy-MM-dd", {
5939
+ locale: ptBR,
5940
+ });
5941
+ var formattedStartsAt = format(parse(formatDateString(item.startsAt), "yyyy-MM-dd HH:mm:ss", new Date()), "yyyy-MM-dd", {
5942
+ locale: ptBR,
5943
+ });
5944
+ var formattedEndsAt = format(parse(formatDateString(item.endsAt), "yyyy-MM-dd HH:mm:ss", new Date()), "yyyy-MM-dd", {
5945
+ locale: ptBR,
5946
+ });
5947
+ if (formattedCteAt >= formattedStartsAt && formattedCteAt <= formattedEndsAt) {
5948
+ return true;
5949
+ }
5950
+ }
5951
+ return false;
5952
+ });
5953
+ };
5954
+
5955
+ var getContractRouteFromFreight = function (contracts, freight) {
5956
+ var _a;
5957
+ var contract = getContractFromFreight(contracts, freight);
5958
+ if (contract) {
5959
+ var routesToStateDestination = (_a = contract.DomainSlaRoute) === null || _a === void 0 ? void 0 : _a.filter(function (it) { var _a; return it.stateDestinationId === ((_a = freight.cityDestination) === null || _a === void 0 ? void 0 : _a.state.id); });
5960
+ console.log({
5961
+ routesToStateDestination: routesToStateDestination,
5962
+ });
5963
+ if (routesToStateDestination === null || routesToStateDestination === void 0 ? void 0 : routesToStateDestination.length) {
5964
+ var routesToCityDestination = routesToStateDestination.filter(function (it) { return it.cityDestinationId === freight.cityDestinationId; });
5965
+ if (routesToCityDestination === null || routesToCityDestination === void 0 ? void 0 : routesToCityDestination.length) {
5966
+ console.log({
5967
+ routesToCityDestination: routesToCityDestination,
5968
+ });
5969
+ var routeFromCityOriginAndToCityDestination = routesToCityDestination.find(function (it) { return it.cityOriginId === freight.cityOriginId; });
5970
+ if (routeFromCityOriginAndToCityDestination) {
5971
+ console.log({
5972
+ routeFromCityOriginAndToCityDestination: routeFromCityOriginAndToCityDestination,
5973
+ });
5974
+ return routeFromCityOriginAndToCityDestination;
5975
+ }
5976
+ else {
5977
+ var routeFromStateOriginWithoutCity = routesToCityDestination.find(function (it) { var _a, _b; return it.stateOriginId === ((_b = (_a = freight.cityOrigin) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.id) && it.cityOriginId === null; });
5978
+ if (routeFromStateOriginWithoutCity) {
5979
+ console.log({
5980
+ routeFromStateOriginWithoutCity: routeFromStateOriginWithoutCity,
5981
+ });
5982
+ return routeFromStateOriginWithoutCity;
5983
+ }
5984
+ else {
5985
+ var routeWithoutCityAndStateOrigin = routesToCityDestination.find(function (it) { return it.stateOriginId === null && it.cityOriginId === null; });
5986
+ if (routeWithoutCityAndStateOrigin) {
5987
+ console.log({
5988
+ routeWithoutCityAndStateOrigin: routeWithoutCityAndStateOrigin,
5989
+ });
5990
+ return routeWithoutCityAndStateOrigin;
5991
+ }
5992
+ }
5993
+ }
5994
+ }
5995
+ else {
5996
+ var routesWithoutCityDestination = routesToStateDestination.filter(function (it) { return it.cityDestinationId === null; });
5997
+ var routesFromStateOrigin = routesWithoutCityDestination.filter(function (it) { var _a, _b; return it.stateOriginId === ((_b = (_a = freight.cityOrigin) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.id); });
5998
+ if (routesFromStateOrigin === null || routesFromStateOrigin === void 0 ? void 0 : routesFromStateOrigin.length) {
5999
+ var routeFromCityOrigin = routesFromStateOrigin.find(function (it) { return it.cityOriginId === freight.cityOriginId; });
6000
+ if (routeFromCityOrigin) {
6001
+ console.log({
6002
+ routeFromCityOrigin: routeFromCityOrigin,
6003
+ });
6004
+ return routeFromCityOrigin;
6005
+ }
6006
+ else {
6007
+ var routeFromStateOrigin = routesFromStateOrigin.find(function (it) { var _a, _b; return it.stateOriginId === ((_b = (_a = freight.cityOrigin) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.id) && it.cityOriginId === null; });
6008
+ if (routeFromStateOrigin) {
6009
+ console.log({
6010
+ routeFromStateOrigin: routeFromStateOrigin
6011
+ });
6012
+ return routeFromStateOrigin;
6013
+ }
6014
+ }
6015
+ }
6016
+ else {
6017
+ var routeFromStateDestination = routesToStateDestination.find(function (it) { var _a, _b; return it.stateDestinationId === ((_b = (_a = freight.cityDestination) === null || _a === void 0 ? void 0 : _a.state) === null || _b === void 0 ? void 0 : _b.id) && it.cityDestinationId === null && it.cityOriginId === null && it.stateOriginId === null; });
6018
+ if (routeFromStateDestination) {
6019
+ console.log({
6020
+ routeFromStateDestination: routeFromStateDestination,
6021
+ });
6022
+ return routeFromStateDestination;
6023
+ }
6024
+ }
6025
+ }
6026
+ }
6027
+ }
6028
+ return false;
6029
+ };
6030
+
6031
+ function getConfigurationFromDomain(domainConfigurations, configurationName) {
6032
+ return domainConfigurations.find(function (i) { return i.name === configurationName; });
6033
+ }
6034
+
6035
+ var getCookies = function (cookies) {
6036
+ if (cookies) {
6037
+ var data_1 = {};
6038
+ cookies
6039
+ .split(';')
6040
+ .map(function (item) { return item.trim().split('='); })
6041
+ .forEach(function (item) { return (data_1[item[0]] = item[1]); });
6042
+ return data_1;
6043
+ }
6044
+ else {
6045
+ return {};
6046
+ }
6047
+ };
6048
+
6049
+ function getDataFromToken(token) {
6050
+ var jwtDataBase64 = token.split('.')[1];
6051
+ var data = JSON.parse(Buffer.from(jwtDataBase64, 'base64').toString());
6052
+ if (data.exp * 1000 < Date.now()) {
6053
+ throw new Error('Token expirado.');
6054
+ }
6055
+ return data;
6056
+ }
6057
+
6058
+ exports.ApplicationColumnNameEnum = void 0;
6059
+ (function (ApplicationColumnNameEnum) {
6060
+ ApplicationColumnNameEnum["DEPARTURE_AT"] = "departureAt";
6061
+ ApplicationColumnNameEnum["ARRIVAL_AT"] = "arrivalAt";
6062
+ ApplicationColumnNameEnum["CLEARANCE_AT"] = "clearanceAt";
6063
+ ApplicationColumnNameEnum["DELIVERY_AT"] = "deliveryAt";
6064
+ ApplicationColumnNameEnum["CREATED_AT"] = "createdAt";
6065
+ })(exports.ApplicationColumnNameEnum || (exports.ApplicationColumnNameEnum = {}));
6066
+
6067
+ exports.ApplicationEnum = void 0;
6068
+ (function (ApplicationEnum) {
6069
+ ApplicationEnum[ApplicationEnum["B2M_CORE"] = 1] = "B2M_CORE";
6070
+ ApplicationEnum[ApplicationEnum["TMS"] = 2] = "TMS";
6071
+ ApplicationEnum[ApplicationEnum["SPOT"] = 3] = "SPOT";
6072
+ ApplicationEnum[ApplicationEnum["TRACK_PROCESSES"] = 4] = "TRACK_PROCESSES";
6073
+ ApplicationEnum[ApplicationEnum["RATECARD_MANAGEMENT"] = 5] = "RATECARD_MANAGEMENT";
6074
+ ApplicationEnum[ApplicationEnum["SLA"] = 6] = "SLA";
6075
+ ApplicationEnum[ApplicationEnum["AUDIT"] = 7] = "AUDIT";
6076
+ })(exports.ApplicationEnum || (exports.ApplicationEnum = {}));
6077
+
6078
+ exports.CountryEnum = void 0;
6079
+ (function (CountryEnum) {
6080
+ CountryEnum[CountryEnum["BRAZIL"] = 1] = "BRAZIL";
6081
+ })(exports.CountryEnum || (exports.CountryEnum = {}));
6082
+
6083
+ exports.CurrencyEnum = void 0;
6084
+ (function (CurrencyEnum) {
6085
+ CurrencyEnum[CurrencyEnum["REAL"] = 1] = "REAL";
6086
+ CurrencyEnum[CurrencyEnum["DOLAR"] = 2] = "DOLAR";
6087
+ CurrencyEnum[CurrencyEnum["EURO"] = 3] = "EURO";
6088
+ CurrencyEnum[CurrencyEnum["IENE"] = 4] = "IENE";
6089
+ })(exports.CurrencyEnum || (exports.CurrencyEnum = {}));
6090
+
6091
+ exports.DomainConfigurationEnum = void 0;
6092
+ (function (DomainConfigurationEnum) {
6093
+ DomainConfigurationEnum["CLEARANCE_DAYS"] = "CLEARANCE_DAYS";
6094
+ DomainConfigurationEnum["CARGO_REMOVAL_DAYS"] = "CARGO_REMOVAL_DAYS";
6095
+ DomainConfigurationEnum["DELIVERY_DAYS"] = "DELIVERY_DAYS";
6096
+ DomainConfigurationEnum["DEMURRAGE_EXPIRY_NOTIFICATION_DAYS"] = "DEMURRAGE_EXPIRY_NOTIFICATION_DAYS";
6097
+ DomainConfigurationEnum["INVOICE_EXPIRY_NOTIFICATION_DAYS"] = "INVOICE_EXPIRY_NOTIFICATION_DAYS";
6098
+ })(exports.DomainConfigurationEnum || (exports.DomainConfigurationEnum = {}));
6099
+
6100
+ exports.DomainTypeEnum = void 0;
6101
+ (function (DomainTypeEnum) {
6102
+ DomainTypeEnum[DomainTypeEnum["TMS"] = 1] = "TMS";
6103
+ DomainTypeEnum[DomainTypeEnum["SPOT"] = 2] = "SPOT";
6104
+ DomainTypeEnum[DomainTypeEnum["PROVIDER"] = 3] = "PROVIDER";
6105
+ DomainTypeEnum[DomainTypeEnum["FREIGHT_FORWARDER"] = 4] = "FREIGHT_FORWARDER";
6106
+ DomainTypeEnum[DomainTypeEnum["DISPATCHER"] = 5] = "DISPATCHER";
6107
+ DomainTypeEnum[DomainTypeEnum["B2M_CLIENT"] = 6] = "B2M_CLIENT";
6108
+ })(exports.DomainTypeEnum || (exports.DomainTypeEnum = {}));
6109
+
6110
+ exports.FeeCalculationTypeEnum = void 0;
6111
+ (function (FeeCalculationTypeEnum) {
6112
+ FeeCalculationTypeEnum[FeeCalculationTypeEnum["FIXED"] = 1] = "FIXED";
6113
+ FeeCalculationTypeEnum[FeeCalculationTypeEnum["TAXED_WEIGHT"] = 2] = "TAXED_WEIGHT";
6114
+ FeeCalculationTypeEnum[FeeCalculationTypeEnum["INTERNATIONAL_CHARGE"] = 3] = "INTERNATIONAL_CHARGE";
6115
+ FeeCalculationTypeEnum[FeeCalculationTypeEnum["CONVERSION_TAX"] = 4] = "CONVERSION_TAX";
6116
+ FeeCalculationTypeEnum[FeeCalculationTypeEnum["CUBED_WEIGHT"] = 5] = "CUBED_WEIGHT";
6117
+ FeeCalculationTypeEnum[FeeCalculationTypeEnum["COMMODITY_VALUE"] = 6] = "COMMODITY_VALUE";
6118
+ FeeCalculationTypeEnum[FeeCalculationTypeEnum["FRACTIONED"] = 7] = "FRACTIONED";
6119
+ FeeCalculationTypeEnum[FeeCalculationTypeEnum["FREIGHT"] = 8] = "FREIGHT";
6120
+ FeeCalculationTypeEnum[FeeCalculationTypeEnum["TOTAL_PERCENTAGE"] = 9] = "TOTAL_PERCENTAGE";
6121
+ FeeCalculationTypeEnum[FeeCalculationTypeEnum["MIN_VALUE"] = 10] = "MIN_VALUE";
6122
+ FeeCalculationTypeEnum[FeeCalculationTypeEnum["SUM_CONTAINERS"] = 11] = "SUM_CONTAINERS";
6123
+ })(exports.FeeCalculationTypeEnum || (exports.FeeCalculationTypeEnum = {}));
6124
+
6125
+ exports.FeeCategoryEnum = void 0;
6126
+ (function (FeeCategoryEnum) {
6127
+ FeeCategoryEnum[FeeCategoryEnum["ORIGIN"] = 1] = "ORIGIN";
6128
+ FeeCategoryEnum[FeeCategoryEnum["INTERNATIONAL"] = 2] = "INTERNATIONAL";
6129
+ FeeCategoryEnum[FeeCategoryEnum["DESTINATION"] = 3] = "DESTINATION";
6130
+ FeeCategoryEnum[FeeCategoryEnum["DELIVERY"] = 4] = "DELIVERY";
6131
+ FeeCategoryEnum[FeeCategoryEnum["ADDITIONAL"] = 5] = "ADDITIONAL";
6132
+ FeeCategoryEnum[FeeCategoryEnum["PICKUP"] = 6] = "PICKUP";
6133
+ FeeCategoryEnum[FeeCategoryEnum["FREIGHT"] = 7] = "FREIGHT";
6134
+ FeeCategoryEnum[FeeCategoryEnum["FEES"] = 8] = "FEES";
6135
+ FeeCategoryEnum[FeeCategoryEnum["TAXES"] = 9] = "TAXES";
6136
+ })(exports.FeeCategoryEnum || (exports.FeeCategoryEnum = {}));
6137
+
6138
+ exports.ModalEnum = void 0;
6139
+ (function (ModalEnum) {
6140
+ ModalEnum[ModalEnum["AIR"] = 1] = "AIR";
6141
+ ModalEnum[ModalEnum["OCEAN_FCL"] = 2] = "OCEAN_FCL";
6142
+ ModalEnum[ModalEnum["OCEAN_LCL"] = 3] = "OCEAN_LCL";
6143
+ ModalEnum[ModalEnum["ROAD_FTL"] = 4] = "ROAD_FTL";
6144
+ ModalEnum[ModalEnum["ROAD_LTL"] = 5] = "ROAD_LTL";
6145
+ })(exports.ModalEnum || (exports.ModalEnum = {}));
6146
+
6147
+ exports.NotificationTypeEnum = void 0;
6148
+ (function (NotificationTypeEnum) {
6149
+ NotificationTypeEnum[NotificationTypeEnum["USER_NOTIFICATION"] = 1] = "USER_NOTIFICATION";
6150
+ NotificationTypeEnum[NotificationTypeEnum["DOMAIN_NOTIFICATION"] = 2] = "DOMAIN_NOTIFICATION";
6151
+ })(exports.NotificationTypeEnum || (exports.NotificationTypeEnum = {}));
6152
+
6153
+ exports.PermissionEnum = void 0;
6154
+ (function (PermissionEnum) {
6155
+ PermissionEnum[PermissionEnum["B2M_ADMIN"] = 1] = "B2M_ADMIN";
6156
+ PermissionEnum[PermissionEnum["DOMAIN_ADMIN"] = 2] = "DOMAIN_ADMIN";
6157
+ PermissionEnum[PermissionEnum["TMS"] = 3] = "TMS";
6158
+ PermissionEnum[PermissionEnum["SPOT"] = 4] = "SPOT";
6159
+ PermissionEnum[PermissionEnum["SPOT_PROVIDER"] = 5] = "SPOT_PROVIDER";
6160
+ PermissionEnum[PermissionEnum["TRACK_PROCESSES"] = 6] = "TRACK_PROCESSES";
6161
+ PermissionEnum[PermissionEnum["DISPATCHER"] = 7] = "DISPATCHER";
6162
+ PermissionEnum[PermissionEnum["RATECARD_MANAGEMENT"] = 8] = "RATECARD_MANAGEMENT";
6163
+ PermissionEnum[PermissionEnum["SLA"] = 9] = "SLA";
6164
+ })(exports.PermissionEnum || (exports.PermissionEnum = {}));
6165
+
6166
+ exports.SpotStatusEnum = void 0;
6167
+ (function (SpotStatusEnum) {
6168
+ SpotStatusEnum[SpotStatusEnum["DRAFT"] = 1] = "DRAFT";
6169
+ SpotStatusEnum[SpotStatusEnum["OPEN"] = 2] = "OPEN";
6170
+ SpotStatusEnum[SpotStatusEnum["CLOSED"] = 3] = "CLOSED";
6171
+ SpotStatusEnum[SpotStatusEnum["FINISHED"] = 4] = "FINISHED";
6172
+ })(exports.SpotStatusEnum || (exports.SpotStatusEnum = {}));
6173
+
6174
+ exports.TrackProcessProviderTypeEnum = void 0;
6175
+ (function (TrackProcessProviderTypeEnum) {
6176
+ TrackProcessProviderTypeEnum[TrackProcessProviderTypeEnum["FREIGHT_FORWARDER"] = 1] = "FREIGHT_FORWARDER";
6177
+ TrackProcessProviderTypeEnum[TrackProcessProviderTypeEnum["DISPATCHER"] = 2] = "DISPATCHER";
6178
+ TrackProcessProviderTypeEnum[TrackProcessProviderTypeEnum["TERMINAL"] = 3] = "TERMINAL";
6179
+ TrackProcessProviderTypeEnum[TrackProcessProviderTypeEnum["SHIPPING_COMPANY"] = 4] = "SHIPPING_COMPANY";
6180
+ TrackProcessProviderTypeEnum[TrackProcessProviderTypeEnum["OTHERS"] = 5] = "OTHERS";
6181
+ })(exports.TrackProcessProviderTypeEnum || (exports.TrackProcessProviderTypeEnum = {}));
6182
+
6183
+ var getFormattedFreightPlaceName = function (freightPlace, modalId, complete, sqlVersion) {
6184
+ var _a, _b;
6185
+ if (complete === void 0) { complete = false; }
6186
+ if (sqlVersion === void 0) { sqlVersion = false; }
6187
+ if (sqlVersion) {
6188
+ var iataText = freightPlace.iata ? "(".concat(freightPlace.iata, ") ") : '';
6189
+ var locationText = freightPlace.location ? " ".concat(freightPlace.location) : '';
6190
+ var countryText = [exports.ModalEnum.OCEAN_FCL, exports.ModalEnum.OCEAN_LCL].includes(modalId) ? "".concat(freightPlace.freightPlaceCountryName, ", ") : '';
6191
+ return "".concat(iataText).concat(freightPlace.name).concat(locationText).concat(complete ? " - ".concat(countryText).concat(freightPlace.freightPlaceRegionName) : '');
6192
+ }
6193
+ else {
6194
+ var iataText = freightPlace.iata ? "(".concat(freightPlace.iata, ") ") : '';
6195
+ var locationText = freightPlace.location ? " ".concat(freightPlace.location) : '';
6196
+ var countryText = [exports.ModalEnum.OCEAN_FCL, exports.ModalEnum.OCEAN_LCL].includes(modalId) ? "".concat((_a = freightPlace.freightPlaceCountry) === null || _a === void 0 ? void 0 : _a.name, ", ") : '';
6197
+ return "".concat(iataText).concat(freightPlace.name).concat(locationText).concat(complete ? " - ".concat(countryText).concat((_b = freightPlace.freightPlaceRegion) === null || _b === void 0 ? void 0 : _b.name) : '');
6198
+ }
6199
+ };
6200
+
6201
+ /******************************************************************************
6202
+ Copyright (c) Microsoft Corporation.
6203
+
6204
+ Permission to use, copy, modify, and/or distribute this software for any
6205
+ purpose with or without fee is hereby granted.
6206
+
6207
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
6208
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
6209
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
6210
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
6211
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
6212
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
6213
+ PERFORMANCE OF THIS SOFTWARE.
6214
+ ***************************************************************************** */
6215
+
6216
+ function __awaiter(thisArg, _arguments, P, generator) {
6217
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6218
+ return new (P || (P = Promise))(function (resolve, reject) {
6219
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6220
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6221
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
6222
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
6223
+ });
6224
+ }
6225
+
6226
+ function __generator(thisArg, body) {
6227
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
6228
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
6229
+ function verb(n) { return function (v) { return step([n, v]); }; }
6230
+ function step(op) {
6231
+ if (f) throw new TypeError("Generator is already executing.");
6232
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
6233
+ 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;
6234
+ if (y = 0, t) op = [op[0] & 2, t.value];
6235
+ switch (op[0]) {
6236
+ case 0: case 1: t = op; break;
6237
+ case 4: _.label++; return { value: op[1], done: false };
6238
+ case 5: _.label++; y = op[1]; op = [0]; continue;
6239
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
6240
+ default:
6241
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
6242
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
6243
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
6244
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
6245
+ if (t[2]) _.ops.pop();
6246
+ _.trys.pop(); continue;
6247
+ }
6248
+ op = body.call(thisArg, _);
6249
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
6250
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
6251
+ }
6252
+ }
6253
+
6254
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
6255
+ var e = new Error(message);
6256
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
6257
+ };
6258
+
6163
6259
  var setFormattedDatesInObjects = function (objectFormat) { return __awaiter(void 0, void 0, void 0, function () {
6164
6260
  var _a, _b, _c, _i, key, formattedDate, _d, _e, _f, _g;
6165
6261
  return __generator(this, function (_h) {
@@ -6222,6 +6318,8 @@ var setFormattedDatesInObjects = function (objectFormat) { return __awaiter(void
6222
6318
 
6223
6319
  exports.formatDateString = formatDateString;
6224
6320
  exports.getConfigurationFromDomain = getConfigurationFromDomain;
6321
+ exports.getContractFromFreight = getContractFromFreight;
6322
+ exports.getContractRouteFromFreight = getContractRouteFromFreight;
6225
6323
  exports.getCookies = getCookies;
6226
6324
  exports.getDataFromToken = getDataFromToken;
6227
6325
  exports.getFormattedFreightPlaceName = getFormattedFreightPlaceName;
package/build/index.js.gz CHANGED
Binary file