mts-booking-library 1.1.2 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/booking/subscriptionBooking.d.ts +14 -5
- package/lib/booking/subscriptionBooking.js +27 -6
- package/lib/index.d.ts +3 -1
- package/lib/types/subscriptions/SubscriptionAvailabilities.d.ts +69 -0
- package/lib/types/subscriptions/SubscriptionAvailabilities.js +2 -0
- package/lib/types/subscriptions/SubscriptionCart.d.ts +39 -0
- package/lib/types/subscriptions/SubscriptionCart.js +2 -0
- package/lib/types/subscriptions/Subscriptions.d.ts +26 -0
- package/lib/types/subscriptions/Subscriptions.js +2 -0
- package/package.json +1 -1
@@ -1,6 +1,8 @@
|
|
1
1
|
import { MTSEnvs } from "../config";
|
2
2
|
import { Cart } from "../types/common/Cart";
|
3
|
-
import {
|
3
|
+
import { GetSubscriptionAvailabilityRequest, GetSubscriptionAvailabilityResponse } from "../types/subscriptions/SubscriptionAvailabilities";
|
4
|
+
import { CreateSubscriptionCartRequest } from "../types/subscriptions/SubscriptionCart";
|
5
|
+
import { Subscription } from "../types/subscriptions/Subscriptions";
|
4
6
|
import { Booking } from "./booking";
|
5
7
|
export declare class SubscriptionBooking extends Booking {
|
6
8
|
private cart?;
|
@@ -19,7 +21,7 @@ export declare class SubscriptionBooking extends Booking {
|
|
19
21
|
* @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
|
20
22
|
* @returns {string[]} The list of possible destinations
|
21
23
|
*/
|
22
|
-
|
24
|
+
getSubscirptionsDestinations(departureStopName: string): Promise<string[]>;
|
23
25
|
/**
|
24
26
|
* This method returns the possible validity types for the subscriptions sold by this seller between the selected departure and destination.
|
25
27
|
* The validity type is the duration of the subscription (1 week, 1 month, etc.). See {@link ValidityTypes} for more details.
|
@@ -27,7 +29,7 @@ export declare class SubscriptionBooking extends Booking {
|
|
27
29
|
* @param {string} destinationStopName The destination stop name (as returned by {@link getSubscriptionsDstinations})
|
28
30
|
* @returns {ValidityTypes[]} The list of possible validity types
|
29
31
|
*/
|
30
|
-
|
32
|
+
getSubscriptionsValidityTypes(departureStopName: string, destinationStopName: string): Promise<SubscriptionBooking.ValidityTypes[]>;
|
31
33
|
/**
|
32
34
|
* This method returns the subscriptions that match the given parameters.
|
33
35
|
* Note that it will always return the subscription for the one-way trip.
|
@@ -37,8 +39,15 @@ export declare class SubscriptionBooking extends Booking {
|
|
37
39
|
* @param {string} validityType The validity type (as returned by {@link getSubscriptionsValidityTypes})
|
38
40
|
* @returns {Array<Subscription>} The subscriptions that match the given parameters
|
39
41
|
*/
|
40
|
-
|
41
|
-
|
42
|
+
getSubscriptions(departureStopName: string, destinationStopName: string, validityType: string): Promise<Subscription[]>;
|
43
|
+
/**
|
44
|
+
* This method returns the availability of the subscription for the given parameters.
|
45
|
+
* Note that, contrary for the previous method, you should make one single request for both the outbound and return trip.
|
46
|
+
* @param {GetSubscriptionAvailabilityRequest} request the request object containing the parameters for the availability check
|
47
|
+
* @returns {GetSubscriptionAvailabilityResponse} The availability of the subscription for the given parameters
|
48
|
+
*/
|
49
|
+
getSubscriptionAvailabilities(request: GetSubscriptionAvailabilityRequest): Promise<GetSubscriptionAvailabilityResponse>;
|
50
|
+
createSubscriptionCart(request: CreateSubscriptionCartRequest): Promise<any>;
|
42
51
|
}
|
43
52
|
export declare namespace SubscriptionBooking {
|
44
53
|
enum ValidityTypes {
|
@@ -69,8 +69,14 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
69
69
|
__extends(SubscriptionBooking, _super);
|
70
70
|
function SubscriptionBooking(env, sub_key, onCartExpiration, debug, access_token, sellerId) {
|
71
71
|
if (debug === void 0) { debug = false; }
|
72
|
+
var _this =
|
72
73
|
// Call Booking constructor
|
73
|
-
|
74
|
+
_super.call(this, env, sub_key, onCartExpiration, debug, access_token, sellerId) || this;
|
75
|
+
var cartId = localStorage.getItem("cartId");
|
76
|
+
if (cartId) {
|
77
|
+
_this.fetchAndSetCart(parseInt(cartId));
|
78
|
+
}
|
79
|
+
return _this;
|
74
80
|
}
|
75
81
|
SubscriptionBooking.prototype.getCart = function () {
|
76
82
|
return this.cart;
|
@@ -135,7 +141,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
135
141
|
* @param {string} departureStopName The departure stop name (as returned by {@link getSubscriptionsDepartures})
|
136
142
|
* @returns {string[]} The list of possible destinations
|
137
143
|
*/
|
138
|
-
SubscriptionBooking.prototype.
|
144
|
+
SubscriptionBooking.prototype.getSubscirptionsDestinations = function (departureStopName) {
|
139
145
|
return __awaiter(this, void 0, void 0, function () {
|
140
146
|
var url;
|
141
147
|
return __generator(this, function (_a) {
|
@@ -151,7 +157,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
151
157
|
* @param {string} destinationStopName The destination stop name (as returned by {@link getSubscriptionsDstinations})
|
152
158
|
* @returns {ValidityTypes[]} The list of possible validity types
|
153
159
|
*/
|
154
|
-
SubscriptionBooking.prototype.
|
160
|
+
SubscriptionBooking.prototype.getSubscriptionsValidityTypes = function (departureStopName, destinationStopName) {
|
155
161
|
return __awaiter(this, void 0, void 0, function () {
|
156
162
|
var url;
|
157
163
|
return __generator(this, function (_a) {
|
@@ -169,7 +175,7 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
169
175
|
* @param {string} validityType The validity type (as returned by {@link getSubscriptionsValidityTypes})
|
170
176
|
* @returns {Array<Subscription>} The subscriptions that match the given parameters
|
171
177
|
*/
|
172
|
-
SubscriptionBooking.prototype.
|
178
|
+
SubscriptionBooking.prototype.getSubscriptions = function (departureStopName, destinationStopName, validityType) {
|
173
179
|
return __awaiter(this, void 0, void 0, function () {
|
174
180
|
var url;
|
175
181
|
return __generator(this, function (_a) {
|
@@ -178,15 +184,30 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
178
184
|
});
|
179
185
|
});
|
180
186
|
};
|
181
|
-
|
187
|
+
/**
|
188
|
+
* This method returns the availability of the subscription for the given parameters.
|
189
|
+
* Note that, contrary for the previous method, you should make one single request for both the outbound and return trip.
|
190
|
+
* @param {GetSubscriptionAvailabilityRequest} request the request object containing the parameters for the availability check
|
191
|
+
* @returns {GetSubscriptionAvailabilityResponse} The availability of the subscription for the given parameters
|
192
|
+
*/
|
193
|
+
SubscriptionBooking.prototype.getSubscriptionAvailabilities = function (request) {
|
182
194
|
return __awaiter(this, void 0, void 0, function () {
|
183
195
|
var url;
|
184
196
|
return __generator(this, function (_a) {
|
185
|
-
url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions/
|
197
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions/availabilities?").concat(new URLSearchParams(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), { outboundRouteId: request.outboundRouteId.toString(), returnRouteId: request.returnRouteId.toString(), outboundDeparturePhysicalAgencyStopId: request.outboundDeparturePhysicalAgencyStopId.toString(), outboundDestinationPhysicalAgencyStopId: request.outboundDestinationPhysicalAgencyStopId.toString(), returnDeparturePhysicalAgencyStopId: request.returnDeparturePhysicalAgencyStopId.toString(), returnDestinationPhysicalAgencyStopId: request.returnDestinationPhysicalAgencyStopId.toString(), numberOfPassengers: request.numberOfPassengers.toString(), validityType: request.validityType })));
|
186
198
|
return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
|
187
199
|
});
|
188
200
|
});
|
189
201
|
};
|
202
|
+
SubscriptionBooking.prototype.createSubscriptionCart = function (request) {
|
203
|
+
return __awaiter(this, void 0, void 0, function () {
|
204
|
+
var url;
|
205
|
+
return __generator(this, function (_a) {
|
206
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/subscriptions");
|
207
|
+
return [2 /*return*/, (0, apiCall_1.makePost)(url, request)];
|
208
|
+
});
|
209
|
+
});
|
210
|
+
};
|
190
211
|
return SubscriptionBooking;
|
191
212
|
}(booking_1.Booking));
|
192
213
|
exports.SubscriptionBooking = SubscriptionBooking;
|
package/lib/index.d.ts
CHANGED
@@ -12,4 +12,6 @@ export { Line } from "./types/services/Line";
|
|
12
12
|
export { Service, ServiceTrip } from "./types/services/Service";
|
13
13
|
export { ServiceCart, ServiceBookingType, CreateServiceCartRequest } from "./types/services/ServiceCart";
|
14
14
|
export { ServiceInfo } from "./types/services/ServiceInfo";
|
15
|
-
export { Subscription } from "./types/subscriptions/
|
15
|
+
export { Subscription } from "./types/subscriptions/Subscriptions";
|
16
|
+
export { GetSubscriptionAvailabilityRequest, GetSubscriptionAvailabilityResponse, SubscriptionCalendarDayPeriodInfo } from "./types/subscriptions/SubscriptionAvailabilities";
|
17
|
+
export { CreateSubscriptionCartRequest, SubscriptionPeriod } from "./types/subscriptions/SubscriptionCart";
|
@@ -0,0 +1,69 @@
|
|
1
|
+
/**
|
2
|
+
* @description This is the object to be passed to `SubscriptionBooking.getSubscrptionAvailabilities`
|
3
|
+
*
|
4
|
+
* @property {number} outboundRouteId - The id of the outbound route.
|
5
|
+
* Its value can be retrieved from {@link Subscription.routeId}, return value of {@link SubscriptionBooking.getSubscriptions} for the oubound subscription.
|
6
|
+
* @property {number} returnRouteId - The id of the return route (0 if the subscription is for a one-way trip)
|
7
|
+
* Its value can be retrieved from {@link Subscription.routeId}, return value of {@link SubscriptionBooking.getSubscriptions} for the return subscription.
|
8
|
+
* @property {number} outboundDeparturePhysicalAgencyStopId - The id of the outbound departure stop.
|
9
|
+
* Its value can be retrieved from {@link Subscription.departurePhysicalAgencyStopId}, return value of {@link SubscriptionBooking.getSubscriptions} for the oubound subscription.
|
10
|
+
* @property {number} outboundDestinationPhysicalAgencyStopId - The id of the outbound destination stop.
|
11
|
+
* Its value can be retrieved from {@link Subscription.destinationPhysicalAgencyStopId}, return value of {@link SubscriptionBooking.getSubscriptions} for the oubound subscription.
|
12
|
+
* @property {number} returnDeparturePhysicalAgencyStopId - The id of the return departure stop (0 if the subscription is for a one-way trip).
|
13
|
+
* Its value can be retrieved from {@link Subscription.departurePhysicalAgencyStopId}, return value of {@link SubscriptionBooking.getSubscriptions} for the return subscription.
|
14
|
+
* @property {number} returnDestinationPhysicalAgencyStopId - The id of the return destination stop (0 if the subscription is for a one-way trip).
|
15
|
+
* Its value can be retrieved from {@link Subscription.destinationPhysicalAgencyStopId}, return value of {@link SubscriptionBooking.getSubscriptions} for the return subscription.
|
16
|
+
* @property {number} numberOfPassengers - The number of passengers to be booked.
|
17
|
+
* @property {string} validityType - The validity type of the subscription (as returned by {@link SubscriptionBooking.getSubscriptionsValidityTypes})
|
18
|
+
*/
|
19
|
+
export type GetSubscriptionAvailabilityRequest = {
|
20
|
+
outboundRouteId: number;
|
21
|
+
returnRouteId: number;
|
22
|
+
outboundDeparturePhysicalAgencyStopId: number;
|
23
|
+
outboundDestinationPhysicalAgencyStopId: number;
|
24
|
+
returnDeparturePhysicalAgencyStopId: number;
|
25
|
+
returnDestinationPhysicalAgencyStopId: number;
|
26
|
+
numberOfPassengers: number;
|
27
|
+
validityType: string;
|
28
|
+
};
|
29
|
+
/**
|
30
|
+
* @description This is the object to be returned by to `SubscriptionBooking.getSubscrptionAvailabilities`,
|
31
|
+
* containing general information about the selected subscription as well as the list of periods in which it is possible to
|
32
|
+
* book the subscription.
|
33
|
+
*
|
34
|
+
* @property {string} departureStopName - The name of the departure stop.
|
35
|
+
* @property {string} destinationStopName - The name of the destination stop.
|
36
|
+
* @property {Date} outboundDepartureTime - The departure time of the outbound trip.
|
37
|
+
* @property {Date} outboundDestinationTime - The destination time of the outbound trip.
|
38
|
+
* @property {Date} returnDepartureTime - The departure time of the return trip.
|
39
|
+
* @property {Date} returnDestinationTime - The destination time of the return trip.
|
40
|
+
* @property {SubscriptionCalendarDayPeriodInfo[]} periods - The list of periods for which the availability of the subscription was checked.
|
41
|
+
*/
|
42
|
+
export type GetSubscriptionAvailabilityResponse = {
|
43
|
+
departureStopName: string;
|
44
|
+
destinationStopName: string;
|
45
|
+
outboundDepartureTime: Date;
|
46
|
+
outboundDestinationTime: Date;
|
47
|
+
returnDepartureTime: Date;
|
48
|
+
returnDestinationTime: Date;
|
49
|
+
periods: SubscriptionCalendarDayPeriodInfo[];
|
50
|
+
};
|
51
|
+
/**
|
52
|
+
* @description This is the object descibing the availability of a subscription for a given period.
|
53
|
+
* Note that it is possible to book a subscription only is both {@link journeyAvailable} and {@link isAvailable} are true.
|
54
|
+
*
|
55
|
+
* @property {string} periodName - The name of the period (e.g. "July 2023")
|
56
|
+
* @property {Date} dateFrom - The start date of the period.
|
57
|
+
* @property {Date} dateTo - The end date of the period.
|
58
|
+
* @property {number} price - The price of the subscription for the given period.
|
59
|
+
* @property {boolean} journeyAvailable - Whether this subscription is available in this period.
|
60
|
+
* @property {boolean} isAvailable - If this subscription is available (i.e. if {@link journeyAvailable} is true), this tells whether it can be booked
|
61
|
+
*/
|
62
|
+
export type SubscriptionCalendarDayPeriodInfo = {
|
63
|
+
periodName: string;
|
64
|
+
dateFrom: Date;
|
65
|
+
dateTo: Date;
|
66
|
+
price: number;
|
67
|
+
journeyAvailable: boolean;
|
68
|
+
isAvailable: boolean;
|
69
|
+
};
|
@@ -0,0 +1,39 @@
|
|
1
|
+
/**
|
2
|
+
* @description This is the object to be passed to `SubscriptionBooking.createSubscriptionCart`,
|
3
|
+
* containing information about the selected subscription.
|
4
|
+
*
|
5
|
+
* @property {number} outboundDeparturePhysicalAgencyStopId - The id of the outbound departure stop.
|
6
|
+
* Its value can be retrieved from {@link Subscription.departurePhysicalAgencyStopId}, return value of {@link SubscriptionBooking.getSubscriptions} for the oubound subscription.
|
7
|
+
* @property {number} outboundDestinationPhysicalAgencyStopId - The id of the outbound destination stop.
|
8
|
+
* Its value can be retrieved from {@link Subscription.destinationPhysicalAgencyStopId}, return value of {@link SubscriptionBooking.getSubscriptions} for the oubound subscription.
|
9
|
+
* @property {number} returnDeparturePhysicalAgencyStopId - The id of the return departure stop (0 if the subscription is for a one-way trip).
|
10
|
+
* Its value can be retrieved from {@link Subscription.departurePhysicalAgencyStopId}, return value of {@link SubscriptionBooking.getSubscriptions} for the return subscription.
|
11
|
+
* @property {number} returnDestinationPhysicalAgencyStopId - The id of the return destination stop (0 if the subscription is for a one-way trip).
|
12
|
+
* Its value can be retrieved from {@link Subscription.destinationPhysicalAgencyStopId}, return value of {@link SubscriptionBooking.getSubscriptions} for the return subscription.
|
13
|
+
* @property {number} outboundRouteId - The id of the outbound route.
|
14
|
+
* Its value can be retrieved from {@link Subscription.routeId}, return value of {@link SubscriptionBooking.getSubscriptions} for the oubound subscription.
|
15
|
+
* @property {number} returnRouteId - The id of the return route (0 if the subscription is for a one-way trip)
|
16
|
+
* Its value can be retrieved from {@link Subscription.routeId}, return value of {@link SubscriptionBooking.getSubscriptions} for the return subscription.
|
17
|
+
* @property {number} numberOfPassengers - The number of passengers to book.
|
18
|
+
* @property {SubscriptionPeriod[]} period - A list of periods for which the subscription should be booked.
|
19
|
+
*/
|
20
|
+
export type CreateSubscriptionCartRequest = {
|
21
|
+
outboundDeparturePhysicalAgencyStopId: number;
|
22
|
+
outboundDestinationPhysicalAgencyStopId: number;
|
23
|
+
returnDeparturePhysicalAgencyStopId: number;
|
24
|
+
returnDestinationPhysicalAgencyStopId: number;
|
25
|
+
outboundRouteId: number;
|
26
|
+
returnRouteId: number;
|
27
|
+
numberOfPassengers: number;
|
28
|
+
period: SubscriptionPeriod[];
|
29
|
+
};
|
30
|
+
/**
|
31
|
+
* @description This is the object that describes which perios should be booked.
|
32
|
+
*
|
33
|
+
* @property {string} dateFrom - The start date of the period as returned by {@link SubscriptionBooking.getSubscrptionAvailabilities}.
|
34
|
+
* @property {string} dateTo - The end date of the period as returned by {@link SubscriptionBooking.getSubscrptionAvailabilities}.
|
35
|
+
*/
|
36
|
+
export type SubscriptionPeriod = {
|
37
|
+
dateFrom: string;
|
38
|
+
dateTo: string;
|
39
|
+
};
|
@@ -0,0 +1,26 @@
|
|
1
|
+
/**
|
2
|
+
* @description This is the object to be returned by to `SubscriptionBooking.getSubscrptions`, containing information about the selected subscription.
|
3
|
+
*
|
4
|
+
* @property {number} departurePhysicalAgencyStopId - The id of the departure stop.
|
5
|
+
* @property {string} departureStopName - The name of the departure stop.
|
6
|
+
* @property {number} destinationPhysicalAgencyStopId - The id of the destination stop.
|
7
|
+
* @property {string} destinationStopName - The name of the destination stop.
|
8
|
+
* @property {string} departureTime - The time of departure from the departureStop.
|
9
|
+
* @property {string} destinationTime - The time of arrival to the destinationStop.
|
10
|
+
* @property {string} lineName - The name of the line on which the subscription is sold.
|
11
|
+
* @property {number} routeId - The id of the route on which the subscription is sold.
|
12
|
+
* @property {string} routeName - The name of the route on which the subscription is sold.
|
13
|
+
* @property {number} sellerId - The id of the seller selling the subscription.
|
14
|
+
*/
|
15
|
+
export type Subscription = {
|
16
|
+
departurePhysicalAgencyStopId: number;
|
17
|
+
departureStopName: string;
|
18
|
+
destinationPhysicalAgencyStopId: number;
|
19
|
+
destinationStopName: string;
|
20
|
+
departureTime: string;
|
21
|
+
destinationTime: string;
|
22
|
+
lineName: string;
|
23
|
+
routeId: number;
|
24
|
+
routeName: string;
|
25
|
+
sellerId: number;
|
26
|
+
};
|