mts-booking-library 2.3.3 → 2.4.1

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/README.md CHANGED
@@ -2,4 +2,7 @@
2
2
  1. `npm i`
3
3
  1. `npm version patch`
4
4
  1. `git push && git push --tags`
5
- 1. `npm publish`
5
+ 1. `npm publish`
6
+
7
+ # Test
8
+ 1. `npm install && npm run test`
@@ -214,11 +214,12 @@ var Booking = /** @class */ (function () {
214
214
  searchParams = new URLSearchParams(__assign(__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 })), { includeSSN: "true" }));
215
215
  url = "".concat(this.config.API_ENDPOINT, "/v3_customers/persons?").concat(searchParams);
216
216
  return [2 /*return*/, this.callGetApi(url, options).then(function (response) {
217
+ var _a, _b;
217
218
  // Check for errors
218
219
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
219
220
  return response;
220
221
  // Return the person details
221
- var person = __assign(__assign({}, response.persons[0]), { socialSecurityNumber: response.persons[0].personDetails.socialSecurityNumber });
222
+ var person = __assign(__assign({}, response.persons[0]), { socialSecurityNumber: (_b = (_a = response.persons[0]) === null || _a === void 0 ? void 0 : _a.personDetails) === null || _b === void 0 ? void 0 : _b.socialSecurityNumber });
222
223
  return person;
223
224
  })];
224
225
  });
@@ -395,11 +395,9 @@ var JourneyBooking = /** @class */ (function (_super) {
395
395
  }))
396
396
  : null;
397
397
  });
398
- return {
399
- buyerDataStatus: response.buyerDataStatus,
400
- buyer: response.buyer,
401
- passengers: passengers
402
- };
398
+ // Return the response
399
+ var res = __assign(__assign({}, response), { passengers: passengers });
400
+ return res;
403
401
  })];
404
402
  });
405
403
  });
@@ -373,11 +373,8 @@ var ServiceBooking = /** @class */ (function (_super) {
373
373
  // Check for errors
374
374
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
375
375
  return response;
376
- return {
377
- buyerDataStatus: response.buyerDataStatus,
378
- buyer: response.buyer,
379
- passengers: []
380
- };
376
+ // Return the response
377
+ return __assign(__assign({}, response), { passengers: [] });
381
378
  })];
382
379
  });
383
380
  });
@@ -169,6 +169,7 @@ export declare namespace SubscriptionBooking {
169
169
  CALENDAR_MONTH = "CALENDAR_MONTH",
170
170
  CALENDAR_SIX_MONTHS = "CALENDAR_SIX_MONTHS",
171
171
  ONE_YEAR = "ONE_YEAR",
172
- CALENDAR_YEAR = "CALENDAR_YEAR"
172
+ CALENDAR_YEAR = "CALENDAR_YEAR",
173
+ FIVE_SECONDS = "FIVE_SECONDS"
173
174
  }
174
175
  }
@@ -421,11 +421,9 @@ var SubscriptionBooking = /** @class */ (function (_super) {
421
421
  }))
422
422
  : null;
423
423
  });
424
- return {
425
- buyerDataStatus: response.buyerDataStatus,
426
- buyer: response.buyer,
427
- passengers: passengers
428
- };
424
+ // Return the response
425
+ var res = __assign(__assign({}, response), { passengers: passengers });
426
+ return res;
429
427
  })];
430
428
  });
431
429
  });
@@ -782,5 +780,6 @@ exports.SubscriptionBooking = SubscriptionBooking;
782
780
  ValidityTypes["CALENDAR_SIX_MONTHS"] = "CALENDAR_SIX_MONTHS";
783
781
  ValidityTypes["ONE_YEAR"] = "ONE_YEAR";
784
782
  ValidityTypes["CALENDAR_YEAR"] = "CALENDAR_YEAR";
783
+ ValidityTypes["FIVE_SECONDS"] = "FIVE_SECONDS";
785
784
  })(ValidityTypes = SubscriptionBooking.ValidityTypes || (SubscriptionBooking.ValidityTypes = {}));
786
785
  })(SubscriptionBooking || (exports.SubscriptionBooking = SubscriptionBooking = {}));
@@ -426,11 +426,8 @@ var TplBooking = /** @class */ (function (_super) {
426
426
  // Check for errors
427
427
  if ((0, ErrorResponse_1.objectIsMTSErrorResponse)(response))
428
428
  return response;
429
- return {
430
- buyerDataStatus: response.buyerDataStatus,
431
- buyer: response.buyer,
432
- passengers: null
433
- };
429
+ // Return the response
430
+ return response;
434
431
  })];
435
432
  });
436
433
  });
@@ -35,23 +35,30 @@ export type GetPersonRequest = {
35
35
  personCode?: string;
36
36
  phoneNumber?: string;
37
37
  };
38
- /**
39
- * @description Represents a passenger in the response of the {@link Booking.getPassengersDetails} method. This type extends the {@link Person} type
40
- * with the `outboundTariffs` and `returnTariffs` properties.
41
- *
42
- * @property {string} outboundNotes - The notes for the outbound trip.
43
- * @property { Map<number, PassengerTariff>} outboundTariffs - A map containing the outbound tariffs for this passenger. The key is the trip id.
44
- * For every trip, the first element the value is the suggested tariff. The other elements are the other tariffs, so that the user can adjust
45
- * the tariff for the passenger.
46
- * @property {string} returnNotes - The notes for the return trip.
47
- * @property { Map<number, PassengerTariff>} returnTariffs - Same of `outboundTariffs`, but for the return trip.
48
- */
38
+ /** @description Represents a passenger in the response of the {@link Booking.getPassengersDetails} method. */
49
39
  export type GetPassenger = Person & {
40
+ /** The notes for the outbound trip. */
50
41
  outboundNotes: string | null;
42
+ /**
43
+ * A map containing the outbound tariffs for this passenger. The key is the trip id.
44
+ * For every trip, the first element the value is the suggested tariff. The other elements are the other tariffs, so that the user can adjust
45
+ * the tariff for the passenger.
46
+ * */
51
47
  outboundTariffs: Map<number, PassengerTariff[]>;
48
+ /** The notes for the return trip. */
52
49
  returnNotes: string | null;
50
+ /** Same of `outboundTariffs`, but for the return trip. */
53
51
  returnTariffs: Map<number, PassengerTariff[]> | null;
52
+ /** Whether the passenger name and last name are required, optional or cannot be specified. */
53
+ passengerNameLastNameOption: PersonDataFieldStatus;
54
+ /** Whether the passenger email is required, optional or cannot be specified. */
55
+ passengerEmailOption: PersonDataFieldStatus;
56
+ /** Whether the passenger phone number is reuqired, optional or cannot be specified. */
57
+ passengerPhoneNumberOption: PersonDataFieldStatus;
58
+ /** Whether the passenger social security number is reuqired, optional or cannot be specified. */
59
+ passengerSSNOption: PersonDataFieldStatus;
54
60
  };
61
+ /** @deprecated Use PersonDataFieldStatus */
55
62
  export declare enum BuyerDataStatus {
56
63
  /** The buyer data are optional. PersonDetails form shall be displayed, but the user can skip it. */
57
64
  OPTIONAL = 0,
@@ -60,14 +67,28 @@ export declare enum BuyerDataStatus {
60
67
  /** The buyer data cannot be specified. PersonDetails form shall not be displayed. */
61
68
  CANNOT_BE_SPECIFIED = 2
62
69
  }
63
- /**
64
- * Represents the response of the {@link getBuyerPassengersDetails} method.
65
- */
70
+ export declare enum PersonDataFieldStatus {
71
+ /** The field (e.g. the buyer's email) is optional. The input shall be displayed, but the user can skip it. */
72
+ OPTIONAL = "OPTIONAL",
73
+ /** The field (e.g. the buyer's email) is required. the input shall be displayed and the user cannot skip it. */
74
+ REQUIRED = "REQUIRED",
75
+ /** The field (e.g. the buyer's email) cannot be specified. The input shall not be displayed. */
76
+ CANNOT_BE_SPECIFIED = "CANNOT_BE_SPECIFIED"
77
+ }
78
+ /** Represents the response of the {@link getBuyerPassengersDetails} method. */
66
79
  export type GetBuyerPassengersDetailsResponse = {
67
- /** Whether the form for the buyer data is required, optional or cannot be specified. */
80
+ /** @deprecated Whether the form for the buyer data is required, optional or cannot be specified. */
68
81
  buyerDataStatus: BuyerDataStatus;
69
82
  /** The {@link Person} object representing the buyer. */
70
83
  buyer: PersonDetails | null;
84
+ /** Whether the buyer name and last name are required, optional or cannot be specified. */
85
+ buyerNameLastNameOption: PersonDataFieldStatus;
86
+ /** Whether the buyer email is required, optional or cannot be specified. */
87
+ buyerEmailOption: PersonDataFieldStatus;
88
+ /** Whether the buyer phone number is reuqired, optional or cannot be specified. */
89
+ buyerPhoneNumberOption: PersonDataFieldStatus;
90
+ /** Whether the buyer social security number is reuqired, optional or cannot be specified. */
91
+ buyerSSNOption: PersonDataFieldStatus;
71
92
  /** An array of {@link GetPassenger} objects representing the passengers. */
72
93
  passengers: GetPassenger[] | null;
73
94
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BuyerDataStatus = exports.initializePerson = exports.DEFAULT_PERSON = void 0;
3
+ exports.PersonDataFieldStatus = exports.BuyerDataStatus = exports.initializePerson = exports.DEFAULT_PERSON = void 0;
4
4
  exports.DEFAULT_PERSON = {
5
5
  id: 0,
6
6
  personCode: "",
@@ -16,6 +16,7 @@ var initializePerson = function (person) {
16
16
  return person;
17
17
  };
18
18
  exports.initializePerson = initializePerson;
19
+ /** @deprecated Use PersonDataFieldStatus */
19
20
  var BuyerDataStatus;
20
21
  (function (BuyerDataStatus) {
21
22
  /** The buyer data are optional. PersonDetails form shall be displayed, but the user can skip it. */
@@ -25,3 +26,12 @@ var BuyerDataStatus;
25
26
  /** The buyer data cannot be specified. PersonDetails form shall not be displayed. */
26
27
  BuyerDataStatus[BuyerDataStatus["CANNOT_BE_SPECIFIED"] = 2] = "CANNOT_BE_SPECIFIED";
27
28
  })(BuyerDataStatus || (exports.BuyerDataStatus = BuyerDataStatus = {}));
29
+ var PersonDataFieldStatus;
30
+ (function (PersonDataFieldStatus) {
31
+ /** The field (e.g. the buyer's email) is optional. The input shall be displayed, but the user can skip it. */
32
+ PersonDataFieldStatus["OPTIONAL"] = "OPTIONAL";
33
+ /** The field (e.g. the buyer's email) is required. the input shall be displayed and the user cannot skip it. */
34
+ PersonDataFieldStatus["REQUIRED"] = "REQUIRED";
35
+ /** The field (e.g. the buyer's email) cannot be specified. The input shall not be displayed. */
36
+ PersonDataFieldStatus["CANNOT_BE_SPECIFIED"] = "CANNOT_BE_SPECIFIED";
37
+ })(PersonDataFieldStatus || (exports.PersonDataFieldStatus = PersonDataFieldStatus = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mts-booking-library",
3
- "version": "2.3.3",
3
+ "version": "2.4.1",
4
4
  "description": "Library for using MyTicketSolution Booking API",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "node-localstorage": "^3.0.5",
23
23
  "prettier": "^3.3.3",
24
24
  "ts-jest": "^29.2.5",
25
- "typescript": "^5.6.3"
25
+ "typescript": "^5.7.2"
26
26
  },
27
27
  "files": [
28
28
  "lib/**/*"
@@ -33,7 +33,7 @@
33
33
  ],
34
34
  "author": "Infoservice s.r.l.",
35
35
  "dependencies": {
36
- "@react-native-async-storage/async-storage": "^2.0.0",
36
+ "@react-native-async-storage/async-storage": "^2.1.0",
37
37
  "axios": "^1.7.7",
38
38
  "zustand": "^4.5.5"
39
39
  }
File without changes
@@ -1,148 +0,0 @@
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,8 +0,0 @@
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;
@@ -1,19 +0,0 @@
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;