mts-booking-library 2.2.3 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ // import { MTSEnvs } from "../config";
3
+ // import { ServiceBooking } from "../booking/serviceBooking";
4
+ // import { CreateServiceCartRequest, ServiceCart } from "../types/services/ServiceCart";
5
+ // import { Service, ServiceTripsResponse } from "../types/services/Service";
6
+ // import { GetBuyerPassengersDetailsResponse } from "../types/common/Person";
7
+ // import { GetPaymentInformationFromGatewayResponse, GetSellerGatewaysResponse, PaymentMethods } from "../types/common/Payment";
8
+ // import { useTestState } from "../mtsStorage";
9
+ // import { SubscriptionBooking } from "../booking/subscriptionBooking";
10
+ // // Load .env file
11
+ // require('dotenv').config();
12
+ // // How to run the test: npm run test -- SubscriptionBooking.test.ts
13
+ // describe("SubscriptionBooking", () => {
14
+ // const timeOut = 120000;
15
+ // const sub_key = process.env.OCP_SUB_KEY_MTS;
16
+ // const access_token = process.env.ACCESS_TOKEN;
17
+ // const sellerId = 8; // ATV
18
+ // // Define localStorage for local testing
19
+ // if (typeof localStorage === "undefined" || localStorage === null) {
20
+ // var LocalStorage = require("node-localstorage").LocalStorage;
21
+ // global.localStorage = new LocalStorage("./scratch");
22
+ // }
23
+ // test("search_tpl", async () => {
24
+ // const booking = new SubscriptionBooking(MTSEnvs.TEST, sub_key!, true, SubscriptionBooking.Languages.EN, access_token, sellerId);
25
+ // // First, get the departures and destinations
26
+ // const departures = await booking.getSubscriptionsDepartures() as string[];
27
+ // expect(departures.length).toBeGreaterThan(0);
28
+ // expect(departures).toContain("BARDOLINO AUTOSTAZIONE");
29
+ // const selectedDeparture = "BARDOLINO AUTOSTAZIONE";
30
+ // const destinations = await booking.getSubscriptionsDestinations(selectedDeparture) as string[];
31
+ // expect(destinations.length).toBeGreaterThan(0);
32
+ // expect(destinations).toContain("GARDA AUTOSTAZIONE");
33
+ // const selectedDestination = "GARDA AUTOSTAZIONE";
34
+ // // Then get the validity types
35
+ // const validityTypes = await booking.getSubscriptionsValidityTypes(selectedDeparture, selectedDestination) as SubscriptionBooking.ValidityTypes[];
36
+ // expect(validityTypes.length).toBeGreaterThan(0);
37
+ // for (const validityType of validityTypes) {
38
+ // // Check that all returned validity types are valid
39
+ // expect(Object.values(SubscriptionBooking.ValidityTypes).includes(validityType)).toBe(true);
40
+ // }
41
+ // }, timeOut);
42
+ // const createCart = async (booking: ServiceBooking): Promise<ServiceCart> => {
43
+ // const servicesResponse = await booking.getServices(ServiceBooking.Currencies.EUR);
44
+ // const services = servicesResponse as Service[];
45
+ // // Build create cart request
46
+ // let tariffsMatrix = services[0].tariffsMatrix;
47
+ // tariffsMatrix[0][0].quantity = 1;
48
+ // const createServiceCartRequest: CreateServiceCartRequest = {
49
+ // currency: ServiceBooking.Currencies.EUR,
50
+ // service: {
51
+ // serviceId: services[0].id,
52
+ // tariffsMatrix: tariffsMatrix
53
+ // }
54
+ // };
55
+ // // Create cart
56
+ // const cart = await booking.createServiceCart(createServiceCartRequest) as ServiceCart;
57
+ // return cart;
58
+ // }
59
+ // test("create_service_cart", async () => {
60
+ // const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
61
+ // const cart = await createCart(booking);
62
+ // // Check that the cartId was saved to the local storage
63
+ // expect(useTestState().getState().cartId).toBe(cart.id);
64
+ // expect(booking.cartId).toBe(cart.id);
65
+ // // Test the booking status (we test only the Buyer and passenger data, as it will always be required)
66
+ // expect(booking.bookingStepsToStatus.get(ServiceBooking.BookingSteps.BUYER_PASSENGERS)).toStrictEqual([ true, false, true ]);
67
+ // expect(booking.bookingStepsToStatus.get(ServiceBooking.BookingSteps.ISSUE)).toStrictEqual([ false, false, true ]);
68
+ // // Test booking due date
69
+ // expect(booking.bookingDueDate?.toISOString()).toBe(new Date(cart.bookingDueDate).toISOString());
70
+ // // Test expired tickets
71
+ // expect(cart.hasIssuedTickets).toBe(false);
72
+ // // Test seller data
73
+ // expect(booking.getSellerId()).toBe(cart.sellerId);
74
+ // expect(cart.sellerPrivacyUrl.length).toBeGreaterThan(0);
75
+ // expect(cart.sellerTermsUrl.length).toBeGreaterThan(0);
76
+ // // Now try to get the cart
77
+ // const newBooking = await ServiceBooking.createBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
78
+ // expect(newBooking.cartId).toBe(cart.id);
79
+ // expect(newBooking.getCart()?.id).toBe(cart.id)
80
+ // expect(newBooking.getSellerId()).toBe(cart.sellerId);
81
+ // // Finally try to delete the cart
82
+ // await booking.deleteCart();
83
+ // expect(booking.getCart()).toBe(undefined);
84
+ // expect(useTestState().getState().cartId).toBe(undefined);
85
+ // }, timeOut);
86
+ // test("get_edit_buyer_data", async () => {
87
+ // const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
88
+ // const cart = await createCart(booking);
89
+ // // First, try to get the buyer data
90
+ // let buyerDataResponse = await booking.getBuyerPassengersDetails();
91
+ // expect((buyerDataResponse as GetBuyerPassengersDetailsResponse).passengers.length).toBe(0);
92
+ // let buyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
93
+ // expect(buyer).toBe(null);
94
+ // // Now try to edit the buyer data
95
+ // buyer = {
96
+ // id: 0,
97
+ // name: "TestName",
98
+ // lastName: "TestSurname",
99
+ // email: "testBookingLib@infos.it",
100
+ // phoneNumber: "+391234567890"
101
+ // }
102
+ // await booking.updateBuyerPassengersDetails(buyer);
103
+ // // Finally, get the buyer data again and check that the data was updated
104
+ // buyerDataResponse = await booking.getBuyerPassengersDetails();
105
+ // const updatedBuyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
106
+ // expect(updatedBuyer.id).toBeGreaterThan(0);
107
+ // expect(updatedBuyer.name).toBe(buyer.name);
108
+ // expect(updatedBuyer.lastName).toBe(buyer.lastName);
109
+ // expect(updatedBuyer.email).toBe(buyer.email);
110
+ // expect(updatedBuyer.phoneNumber).toBe(buyer.phoneNumber);
111
+ // // Finally try to delete the cart
112
+ // await booking.deleteCart();
113
+ // expect(booking.getCart()).toBe(undefined);
114
+ // expect(useTestState().getState().cartId).toBe(undefined);
115
+ // }, timeOut);
116
+ // test("get_gateway_info", async () => {
117
+ // const booking = new ServiceBooking(MTSEnvs.TEST, sub_key!, true, ServiceBooking.Languages.EN);
118
+ // const cart = await createCart(booking);
119
+ // booking.updateSellerId(cart.sellerId);
120
+ // // First, try to get the buyer data
121
+ // let buyerDataResponse = await booking.getBuyerPassengersDetails();
122
+ // expect((buyerDataResponse as GetBuyerPassengersDetailsResponse).passengers.length).toBe(0);
123
+ // let buyer = (buyerDataResponse as GetBuyerPassengersDetailsResponse).buyer;
124
+ // expect(buyer).toBe(null);
125
+ // // Now try to edit the buyer data
126
+ // buyer = {
127
+ // id: 0,
128
+ // name: "TestName",
129
+ // lastName: "TestSurname",
130
+ // email: "testBookingLib@infos.it",
131
+ // phoneNumber: "+391234567890"
132
+ // }
133
+ // await booking.updateBuyerPassengersDetails(buyer);
134
+ // // Try to get the gateways
135
+ // const gateways = await booking.getSellerGateways() as GetSellerGatewaysResponse;
136
+ // if (!gateways.payPalGatewayDTO && !gateways.cardGatewayDTO) {
137
+ // throw new Error("No gateways found");
138
+ // }
139
+ // const gateway = gateways.payPalGatewayDTO ? gateways.payPalGatewayDTO : gateways.cardGatewayDTO;
140
+ // expect(gateway?.id).toBeGreaterThan(0);
141
+ // // Now try to get the info
142
+ // const gatewayInfo = await booking.getPaymentInformationFromGateway(gateway?.id ?? 0) as GetPaymentInformationFromGatewayResponse;
143
+ // // Finally try to delete the cart
144
+ // await booking.deleteCart();
145
+ // expect(booking.getCart()).toBe(undefined);
146
+ // expect(useTestState().getState().cartId).toBe(undefined);
147
+ // }, timeOut);
148
+ // });
@@ -1,6 +1,6 @@
1
1
  import { MTSConfig, MTSEnvs } from "../config";
2
2
  import { ErrorResponse } from "../types/ErrorResponse";
3
- import { Cart, processedStepsToStatus } from "../types/common/Cart";
3
+ import { Cart, CreateUpdateCartRequest, processedStepsToStatus } from "../types/common/Cart";
4
4
  import { GetExtrasForBookingResponse, GetExtrasResponse } from "../types/common/Extra";
5
5
  import { GetPaymentInformationFromGatewayResponse, GetSellerGatewaysResponse, PaymentMethods, IssueCartResponse } from "../types/common/Payment";
6
6
  import { PersonDetails, GetBuyerPassengersDetailsResponse, GetPersonRequest } from "../types/common/Person";
@@ -53,6 +53,7 @@ export declare abstract class Booking {
53
53
  * @returns An {@link ErrorResponse} object in case of error, true otherwise.
54
54
  */
55
55
  markBookingStepCompleted(bookingStep: Booking.BookingSteps, options?: ApiCallOptions): Promise<ErrorResponse | boolean>;
56
+ abstract createCart(request: CreateUpdateCartRequest): Promise<ErrorResponse | any>;
56
57
  abstract deleteCart(): Promise<ErrorResponse | any>;
57
58
  abstract resetBooking(): void;
58
59
  abstract getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
@@ -130,7 +131,9 @@ export declare namespace Booking {
130
131
  SEATS_SELECTION = "BOOKING_STEP_SEATS_SELECTION",
131
132
  EXTRAS = "BOOKING_STEP_EXTRAS",
132
133
  DISCOUNTS = "BOOKING_STEP_DISCOUNTS",
133
- ISSUE = "BOOKING_STEP_ISSUE"
134
+ PAYMENT = "BOOKING_STEP_PAYMENT",
135
+ ISSUE = "BOOKING_STEP_ISSUE",
136
+ SUMMARY = "BOOKING_STEP_SUMMARY"
134
137
  }
135
138
  enum BookingTypes {
136
139
  MLP = "MLP",
@@ -470,7 +470,9 @@ exports.Booking = Booking;
470
470
  BookingSteps["SEATS_SELECTION"] = "BOOKING_STEP_SEATS_SELECTION";
471
471
  BookingSteps["EXTRAS"] = "BOOKING_STEP_EXTRAS";
472
472
  BookingSteps["DISCOUNTS"] = "BOOKING_STEP_DISCOUNTS";
473
+ BookingSteps["PAYMENT"] = "BOOKING_STEP_PAYMENT";
473
474
  BookingSteps["ISSUE"] = "BOOKING_STEP_ISSUE";
475
+ BookingSteps["SUMMARY"] = "BOOKING_STEP_SUMMARY";
474
476
  })(BookingSteps = Booking.BookingSteps || (Booking.BookingSteps = {}));
475
477
  var BookingTypes;
476
478
  (function (BookingTypes) {
@@ -1,4 +1,5 @@
1
1
  import { ErrorResponse } from "../types/ErrorResponse";
2
+ import { CreateUpdateCartRequest } from "../types/common/Cart";
2
3
  import { EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse } from "../types/common/Person";
3
4
  import { AddReductionRequest } from "../types/common/Reduction";
4
5
  import { BusMatrix } from "../types/journeys/BusMatrix";
@@ -88,6 +89,12 @@ export declare class JourneyBooking extends Booking {
88
89
  * @returns The returned journeys that match the given parameters
89
90
  */
90
91
  getJourneys(request: JourneySearchRequest, options?: ApiCallOptions): Promise<ErrorResponse | JourneySearchResult[]>;
92
+ /**
93
+ * This method creates a journey cart (MLP) for the given parameters.
94
+ * @returns The created cart
95
+ */
96
+ createCart(request: CreateUpdateCartRequest, options?: ApiCallOptions): Promise<ErrorResponse | JourneyCart>;
97
+ /** @deprecated Use {@link createCart} instead. */
91
98
  createJourneyCart(journeyCart: CreateJourneyCartRequest, options?: ApiCallOptions): Promise<ErrorResponse | JourneyCart>;
92
99
  /**
93
100
  * @description This method shall be called when the user wants to retrieve information about the buyer and the passengers.
@@ -259,6 +259,45 @@ var JourneyBooking = /** @class */ (function (_super) {
259
259
  });
260
260
  });
261
261
  };
262
+ /**
263
+ * This method creates a journey cart (MLP) for the given parameters.
264
+ * @returns The created cart
265
+ */
266
+ JourneyBooking.prototype.createCart = function (request, options) {
267
+ return __awaiter(this, void 0, void 0, function () {
268
+ var url;
269
+ var _this = this;
270
+ return __generator(this, function (_a) {
271
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts");
272
+ return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
273
+ return __generator(this, function (_a) {
274
+ switch (_a.label) {
275
+ case 0:
276
+ // Check for errors
277
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
278
+ // If there was an error, reset cartGuid and remove it from the mts-storage
279
+ this.resetBooking();
280
+ return [2 /*return*/, response];
281
+ }
282
+ // Fetch the newly created cart & update local properties
283
+ return [4 /*yield*/, this.fetchAndSetCart(response.cartGuid)];
284
+ case 1:
285
+ // Fetch the newly created cart & update local properties
286
+ _a.sent();
287
+ if (!this.cart) {
288
+ // Should already be handled, but just in case
289
+ throw new Error("Could not fetch cart");
290
+ }
291
+ // Update storage
292
+ this.getStorage().getState().updateCartGuid(response.cartGuid);
293
+ return [2 /*return*/, this.cart];
294
+ }
295
+ });
296
+ }); })];
297
+ });
298
+ });
299
+ };
300
+ /** @deprecated Use {@link createCart} instead. */
262
301
  JourneyBooking.prototype.createJourneyCart = function (journeyCart, options) {
263
302
  return __awaiter(this, void 0, void 0, function () {
264
303
  var url, request;
@@ -1,4 +1,5 @@
1
1
  import { ErrorResponse } from "../types/ErrorResponse";
2
+ import { CreateUpdateCartRequest } from "../types/common/Cart";
2
3
  import { PersonDetails, GetBuyerPassengersDetailsResponse } from "../types/common/Person";
3
4
  import { AddReductionRequest } from "../types/common/Reduction";
4
5
  import { Service, ServiceTripsResponse } from "../types/services/Service";
@@ -90,6 +91,12 @@ export declare class ServiceBooking extends Booking {
90
91
  * @returns {ServiceTripsResponse} The returned information about the tour (tripId and hour)
91
92
  */
92
93
  getServiceTrips(serviceId: number, date: string, options?: ApiCallOptions): Promise<ErrorResponse | ServiceTripsResponse>;
94
+ /**
95
+ * This method creates a service cart for the given parameters.
96
+ * @returns The created cart
97
+ */
98
+ createCart(request: CreateUpdateCartRequest, options?: ApiCallOptions): Promise<ErrorResponse | ServiceCart>;
99
+ /** @deprecated Use {@link createCart} instead. */
93
100
  createServiceCart(serviceCart: CreateServiceCartRequest, options?: ApiCallOptions): Promise<ErrorResponse | ServiceCart>;
94
101
  /**
95
102
  * @description This method shall be called when the user wants to retrieve information about the buyer and the passengers.
@@ -258,6 +258,45 @@ var ServiceBooking = /** @class */ (function (_super) {
258
258
  });
259
259
  });
260
260
  };
261
+ /**
262
+ * This method creates a service cart for the given parameters.
263
+ * @returns The created cart
264
+ */
265
+ ServiceBooking.prototype.createCart = function (request, options) {
266
+ return __awaiter(this, void 0, void 0, function () {
267
+ var url;
268
+ var _this = this;
269
+ return __generator(this, function (_a) {
270
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts");
271
+ return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
272
+ return __generator(this, function (_a) {
273
+ switch (_a.label) {
274
+ case 0:
275
+ // Check for errors
276
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
277
+ // If there was an error, reset cartGuid and remove it from the mts-storage
278
+ this.resetBooking();
279
+ return [2 /*return*/, response];
280
+ }
281
+ // Fetch the newly created cart & update local properties
282
+ return [4 /*yield*/, this.fetchAndSetCart(response.cartGuid)];
283
+ case 1:
284
+ // Fetch the newly created cart & update local properties
285
+ _a.sent();
286
+ if (!this.cart) {
287
+ // Should already be handled, but just in case
288
+ throw new Error("Could not fetch cart");
289
+ }
290
+ // Update storage
291
+ this.getStorage().getState().updateCartGuid(response.cartGuid);
292
+ return [2 /*return*/, this.cart];
293
+ }
294
+ });
295
+ }); })];
296
+ });
297
+ });
298
+ };
299
+ /** @deprecated Use {@link createCart} instead. */
261
300
  ServiceBooking.prototype.createServiceCart = function (serviceCart, options) {
262
301
  return __awaiter(this, void 0, void 0, function () {
263
302
  var url;
@@ -1,4 +1,5 @@
1
1
  import { ErrorResponse } from "../types/ErrorResponse";
2
+ import { CreateUpdateCartRequest } from "../types/common/Cart";
2
3
  import { EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse } from "../types/common/Person";
3
4
  import { AddReductionRequest } from "../types/common/Reduction";
4
5
  import { GetSubscriptionAvailabilityRequest, GetSubscriptionAvailabilityResponse } from "../types/subscriptions/SubscriptionAvailabilities";
@@ -104,9 +105,9 @@ export declare class SubscriptionBooking extends Booking {
104
105
  * @returns The availability of the subscription for the given parameters
105
106
  */
106
107
  getSubscriptionAvailabilities(request: GetSubscriptionAvailabilityRequest, options?: ApiCallOptions): Promise<ErrorResponse | GetSubscriptionAvailabilityResponse>;
108
+ createCart(request: CreateUpdateCartRequest): Promise<never>;
107
109
  /**
108
110
  * This method creates a subscription cart for the given parameters.
109
- * @param request the request object containing the parameters for the availability check
110
111
  * @returns The created cart
111
112
  */
112
113
  createSubscriptionCart(request: CreateSubscriptionCartRequest, options?: ApiCallOptions): Promise<ErrorResponse | SubscriptionCart>;
@@ -314,9 +314,15 @@ var SubscriptionBooking = /** @class */ (function (_super) {
314
314
  });
315
315
  });
316
316
  };
317
+ SubscriptionBooking.prototype.createCart = function (request) {
318
+ return __awaiter(this, void 0, void 0, function () {
319
+ return __generator(this, function (_a) {
320
+ throw new Error("Method not available for this booking type. Use createSubscriptionCart instead.");
321
+ });
322
+ });
323
+ };
317
324
  /**
318
325
  * This method creates a subscription cart for the given parameters.
319
- * @param request the request object containing the parameters for the availability check
320
326
  * @returns The created cart
321
327
  */
322
328
  SubscriptionBooking.prototype.createSubscriptionCart = function (request, options) {
@@ -1,4 +1,5 @@
1
1
  import { ErrorResponse } from "../types/ErrorResponse";
2
+ import { CreateUpdateCartRequest } from "../types/common/Cart";
2
3
  import { City } from "../types/common/City";
3
4
  import { PersonDetails, GetBuyerPassengersDetailsResponse } from "../types/common/Person";
4
5
  import { AddReductionRequest } from "../types/common/Reduction";
@@ -103,8 +104,11 @@ export declare class TplBooking extends Booking {
103
104
  */
104
105
  getTariffs(superAreaId: number, termsTypeId: number | null, onlyTickets: boolean, onlySubscriptions: boolean, options?: ApiCallOptions): Promise<ErrorResponse | GetTariffsResponse>;
105
106
  /**
106
- * This method allows to create a TPL cart.
107
+ * This method creates a tpl cart for the given parameters.
108
+ * @returns The created cart
107
109
  */
110
+ createCart(request: CreateUpdateCartRequest, options?: ApiCallOptions): Promise<ErrorResponse | TplCart>;
111
+ /** @deprecated Use {@link createCart} instead. */
108
112
  createTplCart(tplCart: CreateTplCartRequest, options?: ApiCallOptions): Promise<ErrorResponse | TplCart>;
109
113
  /**
110
114
  * @description This method shall be called when the user wants to retrieve information about the buyer and the passengers.
@@ -305,8 +305,44 @@ var TplBooking = /** @class */ (function (_super) {
305
305
  });
306
306
  };
307
307
  /**
308
- * This method allows to create a TPL cart.
308
+ * This method creates a tpl cart for the given parameters.
309
+ * @returns The created cart
309
310
  */
311
+ TplBooking.prototype.createCart = function (request, options) {
312
+ return __awaiter(this, void 0, void 0, function () {
313
+ var url;
314
+ var _this = this;
315
+ return __generator(this, function (_a) {
316
+ url = "".concat(this.config.API_ENDPOINT, "/v3_booking/carts");
317
+ return [2 /*return*/, this.callPostApi(url, request, options).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
318
+ return __generator(this, function (_a) {
319
+ switch (_a.label) {
320
+ case 0:
321
+ // Check for errors
322
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
323
+ // If there was an error, reset cartGuid and remove it from the mts-storage
324
+ this.resetBooking();
325
+ return [2 /*return*/, response];
326
+ }
327
+ // Fetch the newly created cart & update local properties
328
+ return [4 /*yield*/, this.fetchAndSetCart(response.cartGuid)];
329
+ case 1:
330
+ // Fetch the newly created cart & update local properties
331
+ _a.sent();
332
+ if (!this.cart) {
333
+ // Should already be handled, but just in case
334
+ throw new Error("Could not fetch cart");
335
+ }
336
+ // Update storage
337
+ this.getStorage().getState().updateCartGuid(response.cartGuid);
338
+ return [2 /*return*/, this.cart];
339
+ }
340
+ });
341
+ }); })];
342
+ });
343
+ });
344
+ };
345
+ /** @deprecated Use {@link createCart} instead. */
310
346
  TplBooking.prototype.createTplCart = function (tplCart, options) {
311
347
  return __awaiter(this, void 0, void 0, function () {
312
348
  var url, processedTariffIdToQuantity, request;
package/lib/index.d.ts CHANGED
@@ -4,6 +4,7 @@ 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 { CreateUpdateCartRequest, CartBooking } from "./types/common/Cart";
7
8
  export { Person, PersonDetails, DEFAULT_PERSON, initializePerson } from "./types/common/Person";
8
9
  export { GetBuyerPassengersDetailsResponse, GetPersonRequest, GetPassenger, BuyerDataStatus, EditPassengerRequestType, EditPassengersDetailsRequest } from "./types/common/Person";
9
10
  export { Tariff, TariffsMatrix, TariffSummary, TariffType, TermsType, PassengerTariff, ExtraTariff } from "./types/common/Tariffs";
package/lib/index.js CHANGED
@@ -16,9 +16,6 @@ Object.defineProperty(exports, "TplBooking", { enumerable: true, get: function (
16
16
  //#region Export Zustand states
17
17
  var mtsStorage_1 = require("./mtsStorage");
18
18
  Object.defineProperty(exports, "useMtsBookingState", { enumerable: true, get: function () { return mtsStorage_1.useMtsBookingState; } });
19
- //#endregion
20
- //#region Export common types
21
- // @note: Cart is not exported because it is extended by other types
22
19
  var Person_1 = require("./types/common/Person");
23
20
  Object.defineProperty(exports, "DEFAULT_PERSON", { enumerable: true, get: function () { return Person_1.DEFAULT_PERSON; } });
24
21
  Object.defineProperty(exports, "initializePerson", { enumerable: true, get: function () { return Person_1.initializePerson; } });
package/lib/mtsStorage.js CHANGED
@@ -44,8 +44,7 @@ var useMtsBookingState = function () {
44
44
  exports.useMtsBookingState = useMtsBookingState;
45
45
  var useTestState = function () {
46
46
  if (typeof localStorage === "undefined" || localStorage === null) {
47
- var LocalStorage = require("node-localstorage").LocalStorage;
48
- global.localStorage = new LocalStorage("./scratch");
47
+ throw new Error("localStorage is not available");
49
48
  }
50
49
  return useMtsBookingLocalState;
51
50
  };
@@ -7,6 +7,37 @@ export declare enum SellingMethod {
7
7
  RESELLER = "RESELLER",
8
8
  MTSAPP = "MTSAPP"
9
9
  }
10
+ export type CreateUpdateCartRequest = {
11
+ /** The unique identifier for the cart.
12
+ * This should be passed during the change process to link the new ticket to the already existing change cart */
13
+ cartGuid?: string;
14
+ /** The currency of the cart. See {@link Booking.Currencies} */
15
+ currency: Booking.Currencies;
16
+ /** The booking to be added to the cart. */
17
+ cartBooking: CartBooking;
18
+ /** The return booking to be added to the cart (e.g. for MLP). */
19
+ returnCartBooking?: CartBooking;
20
+ };
21
+ export type CartBooking = {
22
+ /** A record containing tariff ids as keys and their respective quantities as values. */
23
+ tariffIdToQuantity?: Record<number, number>;
24
+ /** The date of the booking in ISO string format (optional). */
25
+ date?: string;
26
+ /** The id of the trip, if necessary. For example, this is used by services that require a specific trip to be selected, or by MLP booking */
27
+ tripId?: number;
28
+ /** The id of the line, if necessary. For example, this is used by Services */
29
+ lineId?: number;
30
+ /** The start date of the booking, if necessary. For example, this is used by TPL subscriptions. */
31
+ startDate?: string;
32
+ /** If true, then the booking will be the current period (e.g. this month or this year), otherwise it will be the next period. */
33
+ isCurrentPeriod?: boolean;
34
+ /** The PNR of the ticket of reference, if necessary. For example, this is used in TPL when renewing a subscription. */
35
+ pnr?: string;
36
+ /** The id of the OTA Reseller that sold the ticket */
37
+ otaResellerId?: number;
38
+ /** A string in base64 representing the picture of the ticket that was sold */
39
+ otaTicketPicture?: string;
40
+ };
10
41
  /**
11
42
  * @description Cart is the object returned by the API when a cart is created.
12
43
  * Note that depending on the type of booking, this type will be extended with different fields:
@@ -1,6 +1,6 @@
1
1
  import { Tariff } from "../common/Tariffs";
2
2
  /**
3
- * This represents the response of the API {@link TplBooking.getTariffs}.
3
+ * This represents the response of the API {@link TplBooking.getTariffs()}.
4
4
  * @param {Tariff[]} tariffs - The list of available tariffs. This is meant to be a fast access for displaying the data.
5
5
  * In particular, this array is equivalent to `tariffPlanToTariffs[0]`
6
6
  * @param {Map<number, Tariff[]>} tariffPlanToTariffs - A map that associates a tariff plan to the list of tariffs available for that tariff plan.
@@ -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": "2.2.3",
3
+ "version": "2.3.1",
4
4
  "description": "Library for using MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -16,8 +16,10 @@
16
16
  },
17
17
  "license": "ISC",
18
18
  "devDependencies": {
19
- "@types/jest": "^29.5.13",
19
+ "@types/jest": "^29.5.14",
20
+ "dotenv": "^16.4.5",
20
21
  "jest": "^29.7.0",
22
+ "node-localstorage": "^3.0.5",
21
23
  "prettier": "^3.3.3",
22
24
  "ts-jest": "^29.2.5",
23
25
  "typescript": "^5.6.3"
@@ -33,8 +35,6 @@
33
35
  "dependencies": {
34
36
  "@react-native-async-storage/async-storage": "^2.0.0",
35
37
  "axios": "^1.7.7",
36
- "dotenv": "^16.4.5",
37
- "node-localstorage": "^3.0.5",
38
38
  "zustand": "^4.5.5"
39
39
  }
40
40
  }