mts-booking-library 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  import { MTSEnvs } from "../config";
2
2
  import { ErrorResponse } from "../types/ErrorResponse";
3
- import { EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse } from "../types/common/Person";
3
+ import { EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse, Person } from "../types/common/Person";
4
4
  import { BusMatrix } from "../types/journeys/BusMatrix";
5
5
  import { CreateJourneyCartRequest, JourneyCart } from "../types/journeys/JourneyCart";
6
6
  import { JourneySearchRequest, JourneySearchResult } from "../types/journeys/JourneySearch";
@@ -49,6 +49,15 @@ export declare class JourneyBooking extends Booking {
49
49
  * as well as a list of the available tariffs for each trip.
50
50
  */
51
51
  getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
52
+ /**
53
+ * @description This method shall be called when the user wants to retrieve information about an esisting buyer.
54
+ * @param {string} [linkavelCardNumber=undefined] The linkavel card number of the buyer. This parameter is required if linkavelCardPhoneNumber is not set.
55
+ * A linkavelCardNumber is a string of 9 digits.
56
+ * @param {string} [linkavelCardPhoneNumber=undefined] The linkavel card phone number of the buyer. This parameter is required if linkavelCardNumber is not set.
57
+ * @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
58
+ * as well as a list of the available tariffs for each trip.
59
+ */
60
+ getBuyer(linkavelCardNumber?: string, linkavelCardPhoneNumber?: string): Promise<ErrorResponse | Person>;
52
61
  /**
53
62
  * @description This methosd shall be called when the user wants to update the buyer and the passengers information.
54
63
  * @param {EditPassengersDetailsRequest} passengersDetails The object containing the buyer and the passengers information.
@@ -268,6 +268,44 @@ var JourneyBooking = /** @class */ (function (_super) {
268
268
  });
269
269
  });
270
270
  };
271
+ /**
272
+ * @description This method shall be called when the user wants to retrieve information about an esisting buyer.
273
+ * @param {string} [linkavelCardNumber=undefined] The linkavel card number of the buyer. This parameter is required if linkavelCardPhoneNumber is not set.
274
+ * A linkavelCardNumber is a string of 9 digits.
275
+ * @param {string} [linkavelCardPhoneNumber=undefined] The linkavel card phone number of the buyer. This parameter is required if linkavelCardNumber is not set.
276
+ * @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
277
+ * as well as a list of the available tariffs for each trip.
278
+ */
279
+ JourneyBooking.prototype.getBuyer = function (linkavelCardNumber, linkavelCardPhoneNumber) {
280
+ return __awaiter(this, void 0, void 0, function () {
281
+ var buyerPassengersDetails, searchParams, url;
282
+ return __generator(this, function (_a) {
283
+ // First check that it is possible to call this API
284
+ if (!this.cart) {
285
+ throw Error("Cart is not initialized yet");
286
+ }
287
+ buyerPassengersDetails = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.BUYER_PASSENGERS);
288
+ if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
289
+ throw Error("The status of the cart does not allow to call this API");
290
+ }
291
+ if (!linkavelCardNumber && !linkavelCardPhoneNumber) {
292
+ throw Error("At least one of the parameters linkavelCardNumber and linkavelCardPhoneNumber must be set");
293
+ }
294
+ searchParams = new URLSearchParams({
295
+ linkavelCardNumber: linkavelCardNumber !== null && linkavelCardNumber !== void 0 ? linkavelCardNumber : "",
296
+ linkavelCardPhoneNumber: linkavelCardPhoneNumber !== null && linkavelCardPhoneNumber !== void 0 ? linkavelCardPhoneNumber : "",
297
+ });
298
+ url = "".concat(this.config.API_ENDPOINT, "/buyers?").concat(searchParams, "}");
299
+ return [2 /*return*/, this.callGetApi(url).then(function (response) {
300
+ // Check for errors
301
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
302
+ return response;
303
+ }
304
+ return response.buyers[0];
305
+ })];
306
+ });
307
+ });
308
+ };
271
309
  /**
272
310
  * @description This methosd shall be called when the user wants to update the buyer and the passengers information.
273
311
  * @param {EditPassengersDetailsRequest} passengersDetails The object containing the buyer and the passengers information.
@@ -1,7 +1,7 @@
1
1
  import { MTSEnvs } from "../config";
2
2
  import { ErrorResponse } from "../types/ErrorResponse";
3
3
  import { Cart } from "../types/common/Cart";
4
- import { EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse } from "../types/common/Person";
4
+ import { EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse, Person } from "../types/common/Person";
5
5
  import { GetSubscriptionAvailabilityRequest, GetSubscriptionAvailabilityResponse } from "../types/subscriptions/SubscriptionAvailabilities";
6
6
  import { CreateSubscriptionCartRequest, SubscriptionCart } from "../types/subscriptions/SubscriptionCart";
7
7
  import { Subscription } from "../types/subscriptions/Subscriptions";
@@ -72,6 +72,15 @@ export declare class SubscriptionBooking extends Booking {
72
72
  * as well as a list of the available tariffs for each trip.
73
73
  */
74
74
  getBuyerPassengersDetails(): Promise<ErrorResponse | GetBuyerPassengersDetailsResponse>;
75
+ /**
76
+ * @description This method shall be called when the user wants to retrieve information about an esisting buyer.
77
+ * @param {string} [linkavelCardNumber=undefined] The linkavel card number of the buyer. This parameter is required if linkavelCardPhoneNumber is not set.
78
+ * A linkavelCardNumber is a string of 9 digits.
79
+ * @param {string} [linkavelCardPhoneNumber=undefined] The linkavel card phone number of the buyer. This parameter is required if linkavelCardNumber is not set.
80
+ * @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
81
+ * as well as a list of the available tariffs for each trip.
82
+ */
83
+ getBuyer(linkavelCardNumber?: string, linkavelCardPhoneNumber?: string): Promise<ErrorResponse | Person>;
75
84
  /**
76
85
  * @description This methosd shall be called when the user wants to update the buyer and the passengers information.
77
86
  * @param {EditPassengersDetailsRequest} passengersDetails The object containing the buyer and the passengers information.
@@ -317,6 +317,44 @@ var SubscriptionBooking = /** @class */ (function (_super) {
317
317
  });
318
318
  });
319
319
  };
320
+ /**
321
+ * @description This method shall be called when the user wants to retrieve information about an esisting buyer.
322
+ * @param {string} [linkavelCardNumber=undefined] The linkavel card number of the buyer. This parameter is required if linkavelCardPhoneNumber is not set.
323
+ * A linkavelCardNumber is a string of 9 digits.
324
+ * @param {string} [linkavelCardPhoneNumber=undefined] The linkavel card phone number of the buyer. This parameter is required if linkavelCardNumber is not set.
325
+ * @returns An object of type {@link GetBuyerPassengersDetailsResponse} containing the buyer and the passengers information,
326
+ * as well as a list of the available tariffs for each trip.
327
+ */
328
+ SubscriptionBooking.prototype.getBuyer = function (linkavelCardNumber, linkavelCardPhoneNumber) {
329
+ return __awaiter(this, void 0, void 0, function () {
330
+ var buyerPassengersDetails, searchParams, url;
331
+ return __generator(this, function (_a) {
332
+ // First check that it is possible to call this API
333
+ if (!this.cart) {
334
+ throw Error("Cart is not initialized yet");
335
+ }
336
+ buyerPassengersDetails = this.bookingStepsToStatus.get(booking_1.Booking.BookingSteps.BUYER_PASSENGERS);
337
+ if (!buyerPassengersDetails || !buyerPassengersDetails[0]) {
338
+ throw Error("The status of the cart does not allow to call this API");
339
+ }
340
+ if (!linkavelCardNumber && !linkavelCardPhoneNumber) {
341
+ throw Error("At least one of the parameters linkavelCardNumber and linkavelCardPhoneNumber must be set");
342
+ }
343
+ searchParams = new URLSearchParams({
344
+ linkavelCardNumber: linkavelCardNumber !== null && linkavelCardNumber !== void 0 ? linkavelCardNumber : "",
345
+ linkavelCardPhoneNumber: linkavelCardPhoneNumber !== null && linkavelCardPhoneNumber !== void 0 ? linkavelCardPhoneNumber : "",
346
+ });
347
+ url = "".concat(this.config.API_ENDPOINT, "/buyers?").concat(searchParams, "}");
348
+ return [2 /*return*/, this.callGetApi(url).then(function (response) {
349
+ // Check for errors
350
+ if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response)) {
351
+ return response;
352
+ }
353
+ return response.buyers[0];
354
+ })];
355
+ });
356
+ });
357
+ };
320
358
  /**
321
359
  * @description This methosd shall be called when the user wants to update the buyer and the passengers information.
322
360
  * @param {EditPassengersDetailsRequest} passengersDetails The object containing the buyer and the passengers information.
package/lib/index.d.ts CHANGED
@@ -2,7 +2,8 @@ export { Booking } from "./booking/booking";
2
2
  export { JourneyBooking } from "./booking/journeyBooking";
3
3
  export { ServiceBooking } from "./booking/serviceBooking";
4
4
  export { SubscriptionBooking } from "./booking/subscriptionBooking";
5
- export { Person, EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse, DEFAULT_PERSON } from "./types/common/Person";
5
+ export { Person, DEFAULT_PERSON, initializePerson } from "./types/common/Person";
6
+ export { EditPassengerRequestType, EditPassengersDetailsRequest, GetBuyerPassengersDetailsResponse } from "./types/common/Person";
6
7
  export { Tariff, TariffsMatrix, TariffSummary, TariffType, TermsType, PassengerTariff, ExtraTariff } from "./types/common/Tariffs";
7
8
  export { Reduction, AddReductionRequest } from "./types/common/Reduction";
8
9
  export { Gateway, GetSellerGatewaysResponse, GetPaymentInformationFromGatewayResponse, GatewayTypes, PaymentMethods } from "./types/common/Payment";
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.PaymentMethods = exports.GatewayTypes = exports.DEFAULT_PERSON = 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.PaymentMethods = exports.GatewayTypes = exports.initializePerson = exports.DEFAULT_PERSON = 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; } });
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "SubscriptionBooking", { enumerable: true, get: f
15
15
  // @note: Cart is not exported because it is extended by other types
16
16
  var Person_1 = require("./types/common/Person");
17
17
  Object.defineProperty(exports, "DEFAULT_PERSON", { enumerable: true, get: function () { return Person_1.DEFAULT_PERSON; } });
18
+ Object.defineProperty(exports, "initializePerson", { enumerable: true, get: function () { return Person_1.initializePerson; } });
18
19
  var Payment_1 = require("./types/common/Payment");
19
20
  Object.defineProperty(exports, "GatewayTypes", { enumerable: true, get: function () { return Payment_1.GatewayTypes; } });
20
21
  Object.defineProperty(exports, "PaymentMethods", { enumerable: true, get: function () { return Payment_1.PaymentMethods; } });
@@ -18,6 +18,7 @@ export type Person = {
18
18
  notes?: string;
19
19
  };
20
20
  export declare const DEFAULT_PERSON: Person;
21
+ export declare const initializePerson: (person?: Person | undefined | null) => Person;
21
22
  /**
22
23
  * @description Represents the response of the {@link getBuyerPassengersDetails} method.
23
24
  *
@@ -31,18 +32,22 @@ export type GetBuyerPassengersDetailsResponse = {
31
32
  passengers: Person[];
32
33
  tariffs: Map<number, PassengerTariff>;
33
34
  };
35
+ /**
36
+ * @description Represents the type of the passengers array in {@link EditPassengersDetailsRequest}.
37
+ */
38
+ export type EditPassengerRequestType = Person & {
39
+ tripsToTariffs: {
40
+ [tripId: number]: number;
41
+ };
42
+ };
34
43
  /**
35
44
  * @description Represents the passengers details.
36
45
  * This type shall be used as request for the {@link updatePassengersDetails} method.
37
46
  *
38
- * @property {Person[]} passengers - An array of {@link Person} extended by the map `tripsToTariffs` objects representing the passengers.
47
+ * @property {EditPassengerRequestType[]} passengers - An array of {@link Person} extended by the map `tripsToTariffs` objects representing the passengers.
39
48
  * @property {Person} buyer - The {@link Person} object representing the buyer.
40
49
  */
41
50
  export type EditPassengersDetailsRequest = {
42
- passengers: Person[] & {
43
- tripsToTariffs: {
44
- [tripId: number]: number;
45
- };
46
- };
51
+ passengers: EditPassengerRequestType[];
47
52
  buyer: Person;
48
53
  };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // This module contains the types to manage the passengers information
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.DEFAULT_PERSON = void 0;
4
+ exports.initializePerson = exports.DEFAULT_PERSON = void 0;
5
5
  exports.DEFAULT_PERSON = {
6
6
  id: 0,
7
7
  name: '',
@@ -9,3 +9,10 @@ exports.DEFAULT_PERSON = {
9
9
  email: '',
10
10
  phoneNumber: ''
11
11
  };
12
+ var initializePerson = function (person) {
13
+ if (!person) {
14
+ return exports.DEFAULT_PERSON;
15
+ }
16
+ return person;
17
+ };
18
+ exports.initializePerson = initializePerson;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Library for use MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",