mts-booking-library 1.4.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -35,8 +35,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
35
35
  });
36
36
  };
37
37
  var __generator = (this && this.__generator) || function (thisArg, body) {
38
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
39
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
40
  function verb(n) { return function (v) { return step([n, v]); }; }
41
41
  function step(op) {
42
42
  if (f) throw new TypeError("Generator is already executing.");
@@ -99,11 +99,8 @@ var TplBooking = /** @class */ (function (_super) {
99
99
  resellerId: resellerId,
100
100
  dbType: dbType
101
101
  }) || this;
102
- // Set cartId & cartGuid
103
- var _b = _this.getStorage().getState(), cartId = _b.cartId, cartGuid = _b.cartGuid;
104
- if (cartId && restoreState) {
105
- _this.cartId = cartId;
106
- }
102
+ // Set cartGuid
103
+ var cartGuid = _this.getStorage().getState().cartGuid;
107
104
  if (cartGuid && restoreState) {
108
105
  _this.cartGuid = cartGuid;
109
106
  }
@@ -120,16 +117,15 @@ var TplBooking = /** @class */ (function (_super) {
120
117
  };
121
118
  TplBooking.prototype.resetBooking = function () {
122
119
  this.cart = undefined;
123
- this.cartId = undefined;
124
120
  this.cartGuid = undefined;
125
121
  this.bookingStepsToStatus = new Map();
126
122
  this.bookingDueDate = undefined;
127
123
  try {
128
- this.getStorage().getState().updateCartId(undefined, undefined);
124
+ this.getStorage().getState().updateCartGuid(undefined);
129
125
  }
130
126
  catch (e) {
131
127
  if (this.config.ENV !== config_1.MTSEnvs.TEST) {
132
- throw new Error("Error while deleting cartId from storage");
128
+ throw new Error("Error while deleting cartGuid from storage");
133
129
  }
134
130
  console.log(e);
135
131
  }
@@ -145,7 +141,6 @@ var TplBooking = /** @class */ (function (_super) {
145
141
  cartDueDate.setSeconds(cartDueDate.getSeconds() + cart.bookingDueDateRemainingSeconds);
146
142
  if (cartDueDate > new Date() && !cart.hasIssuedTickets) {
147
143
  _this.cart = cart;
148
- _this.cartId = cart.id;
149
144
  _this.cartGuid = cart.guid;
150
145
  _this.bookingDueDate = cartDueDate; // See Booking class
151
146
  // Update the sellerId. This is particularly important in Linkavel
@@ -227,18 +222,17 @@ var TplBooking = /** @class */ (function (_super) {
227
222
  });
228
223
  });
229
224
  };
230
- // TODO: use v3_resources/superAreas
231
225
  /**
232
226
  * This method fetches the list of super areas for a given city. A super area is a region of the city in which
233
227
  * the TPL service is available at a certain price.
234
228
  * @returns An array of {@link SuperArea} objects representing the SuperAreas if the call is successful, an {@link ErrorResponse} object otherwise.
235
229
  */
236
- TplBooking.prototype.getSuperAreas = function (cityId) {
230
+ TplBooking.prototype.getSuperAreas = function (request) {
237
231
  return __awaiter(this, void 0, void 0, function () {
238
232
  var searchParams, url;
239
233
  return __generator(this, function (_a) {
240
- searchParams = new URLSearchParams({ cityId: cityId.toString() });
241
- url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/superAreasByCity?").concat(searchParams);
234
+ searchParams = new URLSearchParams(__assign(__assign({ includeBasicInfo: "true", includeAreaIds: "false", includeTariffIds: "false", includeRouteIds: "false" }, (request.cityId && { cityId: request.cityId.toString() })), (request.tripId && { tripId: request.tripId.toString() })));
235
+ url = "".concat(this.config.API_ENDPOINT, "/v3_resources/superAreas?").concat(searchParams);
242
236
  return [2 /*return*/, this.callGetApi(url).then(function (response) {
243
237
  return (0, ErrorResponse_1.objectIsMTSErrorResponse)(response)
244
238
  ? response
@@ -320,36 +314,32 @@ var TplBooking = /** @class */ (function (_super) {
320
314
  };
321
315
  /**
322
316
  * This method allows to create a TPL cart.
323
- * @param tariffIdToQuantity A map that associates a tariff id (the one chosen by the user) to the number of tickets to buy for that tariff.
324
- * @param currency The currency in which the ticket is priced.
325
- * @param startDate The start date of the ticket. This is optional and should be used only for subscriptions.
326
- * @param isCurrentPeriod Whether the subscription is for the current period. This is optional and should be used only for subscriptions.
327
- * @param renewSubscriptionTicketPNR The PNR of the subscription ticket to renew. This is optional and should be used only for subscriptions.
328
317
  */
329
- TplBooking.prototype.createTplCart = function (tariffIdToQuantity, currency, startDate, isCurrentPeriod, renewSubscriptionTicketPNR) {
318
+ TplBooking.prototype.createTplCart = function (tplCart) {
330
319
  return __awaiter(this, void 0, void 0, function () {
331
320
  var url, processedTariffIdToQuantity, request;
332
321
  var _this = this;
333
322
  return __generator(this, function (_a) {
334
323
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/tpl/carts");
335
324
  processedTariffIdToQuantity = {};
336
- tariffIdToQuantity.forEach(function (value, key) {
325
+ tplCart.tariffIdToQuantity.forEach(function (value, key) {
337
326
  processedTariffIdToQuantity[key] = value;
338
327
  });
339
- request = __assign(__assign(__assign({ tariffIdToQuantity: processedTariffIdToQuantity, currency: currency }, (startDate !== undefined && { startDate: startDate })), (isCurrentPeriod !== undefined && { isCurrentPeriod: isCurrentPeriod })), (renewSubscriptionTicketPNR !== undefined && { renewSubscriptionTicketPNR: renewSubscriptionTicketPNR }));
328
+ request = __assign(__assign(__assign(__assign(__assign({ tariffIdToQuantity: processedTariffIdToQuantity, currency: tplCart.currency }, (tplCart.startDate !== undefined && { startDate: tplCart.startDate })), (tplCart.isCurrentPeriod !== undefined && { isCurrentPeriod: tplCart.isCurrentPeriod })), (tplCart.renewSubscriptionTicketPNR !== undefined && {
329
+ renewSubscriptionTicketPNR: tplCart.renewSubscriptionTicketPNR
330
+ })), (tplCart.otaResellerId !== undefined && { otaResellerId: tplCart.otaResellerId })), (tplCart.otaTicketPicture !== undefined && { otaTicketPicture: tplCart.otaTicketPicture }));
340
331
  // Call the API
341
332
  return [2 /*return*/, this.callPostApi(url, request).then(function (response) {
342
333
  // Check for errors
343
334
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
344
- // If there was an error, reset cartId and remove it from the mts-storage
335
+ // If there was an error, reset cartGuid and remove it from the mts-storage
345
336
  _this.resetBooking();
346
337
  return response;
347
338
  }
348
339
  _this.cart = response.cart;
349
- _this.cartId = response.cart.id;
350
340
  _this.cartGuid = response.cart.guid;
351
- // Save the cartId in the mts-storage
352
- _this.getStorage().getState().updateCartId(response.cart.id, response.cart.guid);
341
+ // Save the cartGuid in the mts-storage
342
+ _this.getStorage().getState().updateCartGuid(response.cart.guid);
353
343
  // Fill the booking process status
354
344
  _this.bookingStepsToStatus = (0, processBookingSteps_1.processBookingSteps)(response.cart.stepsToStatus);
355
345
  var cartDueDate = new Date();
@@ -362,7 +352,7 @@ var TplBooking = /** @class */ (function (_super) {
362
352
  });
363
353
  });
364
354
  };
365
- //#region Buyer data API
355
+ //#region PersonDetails data API
366
356
  /**
367
357
  * @description This method shall be called when the user wants to retrieve information about the buyer and the passengers.
368
358
  * @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
@@ -396,39 +386,6 @@ var TplBooking = /** @class */ (function (_super) {
396
386
  });
397
387
  });
398
388
  };
399
- /**
400
- * @description This method shall be called when the user wants to retrieve information about an esisting buyer.
401
- * @param {GetBuyerRequest} request The object containing the parameters to search the buyer.
402
- * @returns An object of type {@link Buyer} containing the buyer information, or an {@link ErrorResponse} object in case of error.
403
- */
404
- TplBooking.prototype.getBuyer = function (request) {
405
- return __awaiter(this, void 0, void 0, function () {
406
- var buyerPassengersDetails, searchParams, url;
407
- var _a;
408
- return __generator(this, function (_b) {
409
- // First check that it is possible to call this API
410
- if (!this.cart) {
411
- throw Error("Cart is not initialized yet");
412
- }
413
- buyerPassengersDetails = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.BUYER_PASSENGERS);
414
- if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
415
- throw Error("The status of the cart does not allow to call this API");
416
- }
417
- if (!request.personId && !request.personCode && !request.phoneNumber) {
418
- throw Error("At least one of the parameters personId, personCode or phoneNumber must be set");
419
- }
420
- searchParams = new URLSearchParams(__assign(__assign(__assign({}, (request.personId && { personId: (_a = request.personId) === null || _a === void 0 ? void 0 : _a.toString() })), (request.personCode && { personCode: request.personCode })), (request.phoneNumber && { phoneNumber: request.phoneNumber })));
421
- url = "".concat(this.config.API_ENDPOINT, "/v3_customers/persons?").concat(searchParams);
422
- return [2 /*return*/, this.callGetApi(url).then(function (response) {
423
- // Check for errors
424
- if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
425
- return response;
426
- }
427
- return response.persons[0];
428
- })];
429
- });
430
- });
431
- };
432
389
  /**
433
390
  * @description This method shall be called when the user wants to update the buyer information.
434
391
  * @param buyerDetails The object containing the buyer information.
@@ -522,7 +479,7 @@ var TplBooking = /** @class */ (function (_super) {
522
479
  _c.label = 5;
523
480
  case 5:
524
481
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction");
525
- return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), { cartId: this.cartId, cartGuid: this.cartGuid })).then(function (response) {
482
+ return [2 /*return*/, this.callPostApi(url, __assign(__assign({}, request), { cartGuid: this.cartGuid })).then(function (response) {
526
483
  var _a, _b;
527
484
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
528
485
  return response;
@@ -557,7 +514,10 @@ var TplBooking = /** @class */ (function (_super) {
557
514
  if (!discountsStep || !discountsStep[0]) {
558
515
  throw Error("The status of the cart does not allow to call this API");
559
516
  }
560
- queryParams = new URLSearchParams({ tripId: tripId.toString(), cartId: this.cartId.toString(), cartGuid: this.cartGuid });
517
+ queryParams = new URLSearchParams({
518
+ tripId: tripId.toString(),
519
+ cartGuid: this.cartGuid
520
+ });
561
521
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/reduction?").concat(queryParams);
562
522
  return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
563
523
  var _a, _b, _c;
@@ -626,7 +586,7 @@ var TplBooking = /** @class */ (function (_super) {
626
586
  _c.label = 5;
627
587
  case 5:
628
588
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet");
629
- return [2 /*return*/, this.callPostApi(url, { cartId: this.cartId, cartGuid: this.cartGuid }).then(function (response) {
589
+ return [2 /*return*/, this.callPostApi(url, { cartGuid: this.cartGuid }).then(function (response) {
630
590
  var _a, _b;
631
591
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
632
592
  return response;
@@ -656,7 +616,9 @@ var TplBooking = /** @class */ (function (_super) {
656
616
  if ((0, utils_1.isNullOrWhiteSpace)(this.cartGuid)) {
657
617
  throw Error("Cart is not initialized yet");
658
618
  }
659
- queryParams = new URLSearchParams({ cartId: this.cartId.toString(), cartGuid: this.cartGuid });
619
+ queryParams = new URLSearchParams({
620
+ cartGuid: this.cartGuid
621
+ });
660
622
  url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts/payment/wallet?").concat(queryParams);
661
623
  return [2 /*return*/, this.callDeleteApi(url).then(function (response) {
662
624
  var _a, _b, _c;
@@ -768,11 +730,10 @@ exports.TplBooking = TplBooking;
768
730
  case 3: return [2 /*return*/, booking];
769
731
  case 4:
770
732
  error_1 = _c.sent();
771
- // Check if the error is due to an expired cart. In this case, delete the cartId from the mts-storage
733
+ // Check if the error is due to an expired cart. In this case, delete the cartGuid from the mts-storage
772
734
  // This error can occur when the user refreshes the page and the cart has expired
773
735
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(error_1) && error_1.mtsCode === 40053) {
774
- booking.getStorage().getState().updateCartId(undefined, undefined);
775
- booking.cartId = undefined;
736
+ booking.getStorage().getState().updateCartGuid(undefined);
776
737
  booking.cartGuid = undefined;
777
738
  return [2 /*return*/, booking];
778
739
  }
package/lib/index.d.ts CHANGED
@@ -4,13 +4,14 @@ export { ServiceBooking } from "./booking/serviceBooking";
4
4
  export { SubscriptionBooking } from "./booking/subscriptionBooking";
5
5
  export { TplBooking } from "./booking/tplBooking";
6
6
  export { useMtsBookingState } from "./mtsStorage";
7
- export { Person, Buyer, DEFAULT_PERSON, initializePerson } from "./types/common/Person";
8
- export { GetBuyerPassengersDetailsResponse, GetBuyerRequest, GetPassenger, BuyerDataStatus, EditPassengerRequestType, EditPassengersDetailsRequest } from "./types/common/Person";
7
+ export { Person, PersonDetails, DEFAULT_PERSON, initializePerson } from "./types/common/Person";
8
+ export { GetBuyerPassengersDetailsResponse, GetPersonRequest, GetPassenger, BuyerDataStatus, EditPassengerRequestType, EditPassengersDetailsRequest } from "./types/common/Person";
9
9
  export { Tariff, TariffsMatrix, TariffSummary, TariffType, TermsType, PassengerTariff, ExtraTariff } from "./types/common/Tariffs";
10
- export { Reduction, AddReductionRequest } from "./types/common/Reduction";
11
- export { Gateway, GetSellerGatewaysResponse, GetPaymentInformationFromGatewayResponse, IssueTicketsResponse, GatewayTypes, PaymentMethods } from "./types/common/Payment";
12
- export { ReductionType } from "./types/common/Reduction";
10
+ export { ReductionType, Reduction, AddReductionRequest } from "./types/common/Reduction";
11
+ export { Gateway, GetSellerGatewaysResponse, GetPaymentInformationFromGatewayResponse, IssueCartResponse, GatewayTypes, PaymentMethods } from "./types/common/Payment";
13
12
  export { ErrorResponse, objectIsMTSErrorResponse } from "./types/ErrorResponse";
13
+ export { City } from "./types/common/City";
14
+ export { Extra, GetExtrasResponse, GetExtrasForBookingResponse } from "./types/common/Extra";
14
15
  export { BusLayoutCell, BusMatrix, BusCellTypes, SeatStatus } from "./types/journeys/BusMatrix";
15
16
  export { JourneyCart, JourneyBookingType, CreateJourneyCartRequest, TripBookingInfo, DEFAULT_CREATE_JOURNEY_CART } from "./types/journeys/JourneyCart";
16
17
  export { JourneyInfo } from "./types/journeys/JourneyInfo";
@@ -22,8 +23,8 @@ export { Service, ServiceTrip } from "./types/services/Service";
22
23
  export { ServiceCart, ServiceBookingType, CreateServiceCartRequest } from "./types/services/ServiceCart";
23
24
  export { ServiceInfo } from "./types/services/ServiceInfo";
24
25
  export { GetTariffsResponse } from "./types/tpl/GetTariffsResponse";
25
- export { SuperArea } from "./types/tpl/SuperArea";
26
- export { TplCart, TplBookingType, TplBookingInfo } from "./types/tpl/TplCart";
26
+ export { SuperArea, GetSuperAreasRequest } from "./types/tpl/SuperArea";
27
+ export { CreateTplCartRequest, TplCart, TplBookingType, TplBookingInfo } from "./types/tpl/TplCart";
27
28
  export { Subscription } from "./types/subscriptions/Subscriptions";
28
29
  export { GetSubscriptionAvailabilityRequest, GetSubscriptionAvailabilityResponse, SubscriptionCalendarDayPeriodInfo } from "./types/subscriptions/SubscriptionAvailabilities";
29
30
  export { SubscriptionCart, SubscriptionBookingType, CreateSubscriptionCartRequest, SubscriptionPeriod } from "./types/subscriptions/SubscriptionCart";
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_JOURNEY_SEARCH = exports.DEFAULT_CREATE_JOURNEY_CART = exports.SeatStatus = exports.BusCellTypes = exports.objectIsMTSErrorResponse = exports.ReductionType = exports.PaymentMethods = exports.GatewayTypes = exports.BuyerDataStatus = exports.initializePerson = exports.DEFAULT_PERSON = exports.useMtsBookingState = exports.TplBooking = exports.SubscriptionBooking = exports.ServiceBooking = exports.JourneyBooking = exports.Booking = void 0;
3
+ exports.DEFAULT_JOURNEY_SEARCH = exports.DEFAULT_CREATE_JOURNEY_CART = exports.SeatStatus = exports.BusCellTypes = exports.objectIsMTSErrorResponse = exports.PaymentMethods = exports.GatewayTypes = exports.ReductionType = exports.BuyerDataStatus = exports.initializePerson = exports.DEFAULT_PERSON = exports.useMtsBookingState = exports.TplBooking = exports.SubscriptionBooking = exports.ServiceBooking = exports.JourneyBooking = exports.Booking = void 0;
4
4
  //#region Export Booking classes
5
5
  var booking_1 = require("./booking/booking");
6
6
  Object.defineProperty(exports, "Booking", { enumerable: true, get: function () { return booking_1.Booking; } });
@@ -24,11 +24,11 @@ Object.defineProperty(exports, "DEFAULT_PERSON", { enumerable: true, get: functi
24
24
  Object.defineProperty(exports, "initializePerson", { enumerable: true, get: function () { return Person_1.initializePerson; } });
25
25
  var Person_2 = require("./types/common/Person");
26
26
  Object.defineProperty(exports, "BuyerDataStatus", { enumerable: true, get: function () { return Person_2.BuyerDataStatus; } });
27
+ var Reduction_1 = require("./types/common/Reduction");
28
+ Object.defineProperty(exports, "ReductionType", { enumerable: true, get: function () { return Reduction_1.ReductionType; } });
27
29
  var Payment_1 = require("./types/common/Payment");
28
30
  Object.defineProperty(exports, "GatewayTypes", { enumerable: true, get: function () { return Payment_1.GatewayTypes; } });
29
31
  Object.defineProperty(exports, "PaymentMethods", { enumerable: true, get: function () { return Payment_1.PaymentMethods; } });
30
- var Reduction_1 = require("./types/common/Reduction");
31
- Object.defineProperty(exports, "ReductionType", { enumerable: true, get: function () { return Reduction_1.ReductionType; } });
32
32
  var ErrorResponse_1 = require("./types/ErrorResponse");
33
33
  Object.defineProperty(exports, "objectIsMTSErrorResponse", { enumerable: true, get: function () { return ErrorResponse_1.objectIsMTSErrorResponse; } });
34
34
  //#endregion
@@ -1,10 +1,8 @@
1
1
  type MtsBookingState = {
2
- /** @deprecated Please use {@link MtsBookingState.cartGuid} instead, where possible */
3
- cartId: number | undefined;
4
2
  cartGuid: string | undefined;
5
3
  };
6
4
  type MtsBookingAction = {
7
- updateCartId: (cartId: MtsBookingState["cartId"], cartGuid: MtsBookingState["cartGuid"]) => void;
5
+ updateCartGuid: (cartGuid: MtsBookingState["cartGuid"]) => void;
8
6
  resetState: () => void;
9
7
  };
10
8
  export declare const useMtsBookingLocalState: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<MtsBookingState & MtsBookingAction>, "persist"> & {
package/lib/mtsStorage.js CHANGED
@@ -16,17 +16,16 @@ var async_storage_1 = require("@react-native-async-storage/async-storage");
16
16
  var zustand_1 = require("zustand");
17
17
  var middleware_1 = require("zustand/middleware");
18
18
  var INITIAL_STATE = {
19
- cartId: 0,
20
19
  cartGuid: undefined
21
20
  };
22
- var useMtsBookingAsyncState = (0, zustand_1.create)((0, middleware_1.persist)(function (set) { return (__assign(__assign({}, INITIAL_STATE), { updateCartId: function (cartId, cartGuid) {
23
- return set(function () { return ({ cartId: cartId, cartGuid: cartGuid }); });
21
+ var useMtsBookingAsyncState = (0, zustand_1.create)((0, middleware_1.persist)(function (set) { return (__assign(__assign({}, INITIAL_STATE), { updateCartGuid: function (cartGuid) {
22
+ return set(function () { return ({ cartGuid: cartGuid }); });
24
23
  }, resetState: function () { return set(function () { return INITIAL_STATE; }); } })); }, {
25
24
  name: "mts-booking-storage",
26
25
  storage: (0, middleware_1.createJSONStorage)(function () { return async_storage_1.default; })
27
26
  }));
28
- exports.useMtsBookingLocalState = (0, zustand_1.create)((0, middleware_1.persist)(function (set) { return (__assign(__assign({}, INITIAL_STATE), { updateCartId: function (cartId, cartGuid) {
29
- return set(function () { return ({ cartId: cartId, cartGuid: cartGuid }); });
27
+ exports.useMtsBookingLocalState = (0, zustand_1.create)((0, middleware_1.persist)(function (set) { return (__assign(__assign({}, INITIAL_STATE), { updateCartGuid: function (cartGuid) {
28
+ return set(function () { return ({ cartGuid: cartGuid }); });
30
29
  }, resetState: function () { return set(function () { return INITIAL_STATE; }); } })); }, {
31
30
  name: "mts-booking-storage",
32
31
  storage: (0, middleware_1.createJSONStorage)(function () { return localStorage; })
@@ -16,11 +16,6 @@ export declare enum SellingMethod {
16
16
  * - TplCart: {@link TplCart}
17
17
  */
18
18
  export type Cart = {
19
- /**
20
- * The id of the cart
21
- * @deprecated Please use {@link Cart.guid} instead
22
- */
23
- id: number;
24
19
  /** The guid of the cart */
25
20
  guid: string;
26
21
  /** The id of the seller of the tickets in the cart */
@@ -55,7 +55,7 @@ export declare enum GatewayTypes {
55
55
  }
56
56
  /**
57
57
  * This enum contains the possible values for the `paymentMethod` parameter of the
58
- * {@link Booking.issueTickets} function.
58
+ * {@link Booking.issueCart} function.
59
59
  */
60
60
  export declare enum PaymentMethods {
61
61
  /** Pay with card at the Seller/Reseller counter */
@@ -83,7 +83,7 @@ export type Wallet = {
83
83
  walletTransactions: any[];
84
84
  };
85
85
  /**
86
- * @description This type represents the response of the {@link Booking.issueTickets} API.
86
+ * @description This type represents the response of the {@link Booking.issueCart} API.
87
87
  * @param {Wallet} wallet If the booking was performed by a reseller, this field contains the wallet with the updated balance.
88
88
  * @param {string} ticketsSentToEmail This field contains the email address to which the tickets were sent.
89
89
  * If the buyer email was specified, this field will contain the buyer email. Otherwise, if the reseller performed the booking, this
@@ -91,7 +91,7 @@ export type Wallet = {
91
91
  * the MTS email.
92
92
  * @param {string[]} PNRs An array of PNRs associated with the booking.
93
93
  */
94
- export type IssueTicketsResponse = {
94
+ export type IssueCartResponse = {
95
95
  wallet: Wallet | null;
96
96
  ticketsSentToEmail: string;
97
97
  pnrs: string[];
@@ -13,7 +13,7 @@ var GatewayTypes;
13
13
  })(GatewayTypes || (exports.GatewayTypes = GatewayTypes = {}));
14
14
  /**
15
15
  * This enum contains the possible values for the `paymentMethod` parameter of the
16
- * {@link Booking.issueTickets} function.
16
+ * {@link Booking.issueCart} function.
17
17
  */
18
18
  var PaymentMethods;
19
19
  (function (PaymentMethods) {
@@ -18,19 +18,19 @@ export type Person = {
18
18
  /** The notes for this person. */
19
19
  notes?: string;
20
20
  };
21
- export type Buyer = Person & {
21
+ export type PersonDetails = Person & {
22
22
  /** The social security number of the buyer, if provided. */
23
23
  socialSecurityNumber: string | null;
24
24
  };
25
25
  export declare const DEFAULT_PERSON: Person;
26
26
  export declare const initializePerson: (person?: Person | undefined | null) => Person;
27
27
  /**
28
- * @description Represents the request for the {@link Booking.getBuyerFromLinkavelCard} method.
28
+ * @description Represents the request for the {@link Booking.getPerson} method.
29
29
  * @property {number} personId - The unique identifier of the buyer.
30
30
  * @property {string} personCode - The person code of the person (the old linkAvelCardNumber)
31
31
  * @property {string} phoneNumber - The phone number of the person.
32
32
  */
33
- export type GetBuyerRequest = {
33
+ export type GetPersonRequest = {
34
34
  personId?: number;
35
35
  personCode?: string;
36
36
  phoneNumber?: string;
@@ -53,11 +53,11 @@ export type GetPassenger = Person & {
53
53
  returnTariffs: Map<number, PassengerTariff[]> | null;
54
54
  };
55
55
  export declare enum BuyerDataStatus {
56
- /** The buyer data are optional. Buyer form shall be displayed, but the user can skip it. */
56
+ /** The buyer data are optional. PersonDetails form shall be displayed, but the user can skip it. */
57
57
  OPTIONAL = 0,
58
- /** The buyer data are required. Buyer form shall be displayed and the user cannot skip it. */
58
+ /** The buyer data are required. PersonDetails form shall be displayed and the user cannot skip it. */
59
59
  REQUIRED = 1,
60
- /** The buyer data cannot be specified. Buyer form shall not be displayed. */
60
+ /** The buyer data cannot be specified. PersonDetails form shall not be displayed. */
61
61
  CANNOT_BE_SPECIFIED = 2
62
62
  }
63
63
  /**
@@ -67,7 +67,7 @@ export type GetBuyerPassengersDetailsResponse = {
67
67
  /** Whether the form for the buyer data is required, optional or cannot be specified. */
68
68
  buyerDataStatus: BuyerDataStatus;
69
69
  /** The {@link Person} object representing the buyer. */
70
- buyer: Buyer | null;
70
+ buyer: PersonDetails | null;
71
71
  /** An array of {@link GetPassenger} objects representing the passengers. */
72
72
  passengers: GetPassenger[] | null;
73
73
  };
@@ -92,5 +92,5 @@ export type EditPassengersDetailsRequest = {
92
92
  * The {@link Person} object representing the buyer.
93
93
  * It should be null if the buyer data cannot be specified (see {@link GetBuyerPassengersDetailsResponse.buyerDataStatus}).
94
94
  */
95
- buyer: Buyer | null;
95
+ buyer: PersonDetails | null;
96
96
  };
@@ -18,10 +18,10 @@ var initializePerson = function (person) {
18
18
  exports.initializePerson = initializePerson;
19
19
  var BuyerDataStatus;
20
20
  (function (BuyerDataStatus) {
21
- /** The buyer data are optional. Buyer form shall be displayed, but the user can skip it. */
21
+ /** The buyer data are optional. PersonDetails form shall be displayed, but the user can skip it. */
22
22
  BuyerDataStatus[BuyerDataStatus["OPTIONAL"] = 0] = "OPTIONAL";
23
- /** The buyer data are required. Buyer form shall be displayed and the user cannot skip it. */
23
+ /** The buyer data are required. PersonDetails form shall be displayed and the user cannot skip it. */
24
24
  BuyerDataStatus[BuyerDataStatus["REQUIRED"] = 1] = "REQUIRED";
25
- /** The buyer data cannot be specified. Buyer form shall not be displayed. */
25
+ /** The buyer data cannot be specified. PersonDetails form shall not be displayed. */
26
26
  BuyerDataStatus[BuyerDataStatus["CANNOT_BE_SPECIFIED"] = 2] = "CANNOT_BE_SPECIFIED";
27
27
  })(BuyerDataStatus || (exports.BuyerDataStatus = BuyerDataStatus = {}));
@@ -17,21 +17,26 @@ export type TripBookingInfo = {
17
17
  destinationStopId: number;
18
18
  /** A record containing tariff ids as keys and their respective quantities as values. */
19
19
  tariffIdToQuantity: Record<number, number>;
20
+ /** The id of the OTA Reseller that sold the ticket */
21
+ otaResellerId?: number;
22
+ /** A string in base64 representing the picture of the ticket that was sold */
23
+ otaTicketPicture?: string;
20
24
  };
21
25
  /**
22
- * @description This is the object to be passed to `JourneyBooking.createJourneyCart`, containing information about the selected service.
23
- *
24
- * @property {number|undefined} [cartId=0] - The unique identifier for the cart (optional).
25
- * @property {Booking.Currencies} currency - The currency in which the journey is priced.
26
- * @property {TripBookingInfo[]} outboundJourney - Information about outbound journeys. This is an array of {@link TripBookingInfo} objects.
27
- * Note that when searching for journeys, the `trips` property of the {@link JourneySearchResult} object contains an array of {@link Trip} objects.
28
- * Each trip should be mapped into a {@link TripBookingInfo} object.
29
- * @property {TripBookingInfo[] | null} returnJourney - Information about return journeys (optional, can be null). See outboundJourney.
26
+ * @description This is the object to be passed to {@link JourneyBooking.createJourneyCart}, containing information about the selected service.
30
27
  */
31
28
  export type CreateJourneyCartRequest = {
32
- cartId?: number;
29
+ /** The unique identifier for the cart. This should be passed during the change process to link the new ticket to the already existing change cart */
30
+ cartGuid?: string;
31
+ /** The currency in which the journey is priced */
33
32
  currency: Booking.Currencies;
33
+ /**
34
+ * Information about outbound journeys. This is an array of {@link TripBookingInfo} objects.
35
+ * Note that when searching for journeys, the `trips` property of the {@link JourneySearchResult} object contains an array of {@link Trip} objects.
36
+ * Each trip should be mapped into a {@link TripBookingInfo} object.
37
+ */
34
38
  outboundJourney: TripBookingInfo[];
39
+ /** Information about return journeys (optional, can be null). See outboundJourney. */
35
40
  returnJourney: TripBookingInfo[] | null;
36
41
  };
37
42
  export declare const DEFAULT_CREATE_JOURNEY_CART: CreateJourneyCartRequest;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DEFAULT_CREATE_JOURNEY_CART = void 0;
4
4
  var booking_1 = require("../../booking/booking");
5
5
  exports.DEFAULT_CREATE_JOURNEY_CART = {
6
- cartId: 0,
6
+ cartGuid: undefined,
7
7
  currency: booking_1.Booking.Currencies.EUR,
8
8
  outboundJourney: [],
9
9
  returnJourney: null
@@ -19,6 +19,10 @@ export type CreateServiceCartRequest = {
19
19
  date?: string;
20
20
  /** The unique identifier for the trip (optional). */
21
21
  tripId?: number;
22
+ /** The id of the OTA Reseller that sold the ticket */
23
+ otaResellerId?: number;
24
+ /** A string in base64 representing the picture of the ticket that was sold */
25
+ otaTicketPicture?: string;
22
26
  };
23
27
  };
24
28
  /**
@@ -11,3 +11,9 @@ export type SuperArea = {
11
11
  shortName: string;
12
12
  description: string;
13
13
  };
14
+ export type GetSuperAreasRequest = {
15
+ /** The id of the city (as returned by the {@link TplBooking.getCities} method). If present, only the super areas associated with this city will be returned. */
16
+ cityId?: number;
17
+ /** The id of the trip. If present, only the super areas associated with this trip will be returned. This is used by the app. */
18
+ tripId?: number;
19
+ };
@@ -1,6 +1,25 @@
1
1
  import { Booking } from "../../booking/booking";
2
2
  import { Cart } from "../common/Cart";
3
3
  import { TariffSummary } from "../common/Tariffs";
4
+ /**
5
+ * @description This is the object to be passed to {@link TplBooking.createTplCart}, containing information about the selected tpl service.
6
+ */
7
+ export type CreateTplCartRequest = {
8
+ /** The currency in which the ticket is priced. */
9
+ currency: Booking.Currencies;
10
+ /** A map that associates a tariff id (the one chosen by the user) to the number of tickets to buy for that tariff. */
11
+ tariffIdToQuantity: Map<number, number>;
12
+ /** The start date of the ticket. This is optional and should be used only for subscriptions */
13
+ startDate?: string;
14
+ /** Whether the subscription is for the current period. This is optional and should be used only for subscriptions. */
15
+ isCurrentPeriod?: boolean;
16
+ /** The PNR of the subscription ticket to renew. This is optional and should be used only for subscriptions. */
17
+ renewSubscriptionTicketPNR?: string;
18
+ /** The id of the OTA Reseller that sold the ticket */
19
+ otaResellerId?: number;
20
+ /** A string in base64 representing the picture of the ticket that was sold */
21
+ otaTicketPicture?: string;
22
+ };
4
23
  /**
5
24
  * @description Represents a `TplCart`, which extends the {@link Cart} type by including additional
6
25
  * information about the bookings
@@ -27,8 +27,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
27
27
  });
28
28
  };
29
29
  var __generator = (this && this.__generator) || function (thisArg, body) {
30
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
31
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
30
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
31
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
32
32
  function verb(n) { return function (v) { return step([n, v]); }; }
33
33
  function step(op) {
34
34
  if (f) throw new TypeError("Generator is already executing.");
@@ -0,0 +1,8 @@
1
+ /**
2
+ * This method return the ISO string of the date without GMT. An ISO string looks like this: YYYY-MM-DDThh:mm:ss.mmmZ
3
+ * @param {Date | string} date the date to convert
4
+ * @param {boolean} [removeTimezone=true] if true, the timezone will be removed from the ISO string, meaning
5
+ * that the string will look like this: YYYY-MM-DDThh:mm:ss.mmm
6
+ * @returns {string} the ISO string
7
+ */
8
+ export declare const getISOStringWithoutGMT: (date: Date | string | null | undefined, removeTimezone?: boolean) => string | null;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getISOStringWithoutGMT = void 0;
4
+ /**
5
+ * This method return the ISO string of the date without GMT. An ISO string looks like this: YYYY-MM-DDThh:mm:ss.mmmZ
6
+ * @param {Date | string} date the date to convert
7
+ * @param {boolean} [removeTimezone=true] if true, the timezone will be removed from the ISO string, meaning
8
+ * that the string will look like this: YYYY-MM-DDThh:mm:ss.mmm
9
+ * @returns {string} the ISO string
10
+ */
11
+ var getISOStringWithoutGMT = function (date, removeTimezone) {
12
+ if (removeTimezone === void 0) { removeTimezone = true; }
13
+ if (!date)
14
+ return null;
15
+ var newDate = new Date(date);
16
+ var isoString = new Date(newDate.valueOf() - newDate.getTimezoneOffset() * 60000).toISOString();
17
+ return removeTimezone ? isoString.slice(0, -1) : isoString;
18
+ };
19
+ exports.getISOStringWithoutGMT = getISOStringWithoutGMT;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.4.0",
3
+ "version": "2.0.0",
4
4
  "description": "Library for using MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -16,11 +16,11 @@
16
16
  },
17
17
  "license": "ISC",
18
18
  "devDependencies": {
19
- "@types/jest": "^29.5.12",
19
+ "@types/jest": "^29.5.13",
20
20
  "jest": "^29.7.0",
21
21
  "prettier": "^3.3.3",
22
- "ts-jest": "^29.2.4",
23
- "typescript": "^5.5.4"
22
+ "ts-jest": "^29.2.5",
23
+ "typescript": "^5.6.2"
24
24
  },
25
25
  "files": [
26
26
  "lib/**/*"
@@ -31,8 +31,8 @@
31
31
  ],
32
32
  "author": "Infoservice s.r.l.",
33
33
  "dependencies": {
34
- "@react-native-async-storage/async-storage": "^1.24.0",
35
- "axios": "^1.7.4",
34
+ "@react-native-async-storage/async-storage": "^2.0.0",
35
+ "axios": "^1.7.7",
36
36
  "dotenv": "^16.4.5",
37
37
  "node-localstorage": "^3.0.5",
38
38
  "zustand": "^4.5.5"