mts-booking-library 1.2.3 → 1.2.5
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/booking/journeyBooking.d.ts +4 -1
- package/lib/booking/journeyBooking.js +47 -19
- package/lib/booking/serviceBooking.d.ts +4 -1
- package/lib/booking/serviceBooking.js +47 -19
- package/lib/booking/subscriptionBooking.d.ts +2 -1
- package/lib/booking/subscriptionBooking.js +45 -19
- package/lib/types/common/Person.d.ts +15 -5
- package/package.json +1 -1
@@ -21,7 +21,7 @@ export declare class JourneyBooking extends Booking {
|
|
21
21
|
*/
|
22
22
|
constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
|
23
23
|
getCart(): JourneyCart | undefined;
|
24
|
-
|
24
|
+
fetchAndSetCart(cartId: number): Promise<void>;
|
25
25
|
private createCartTimer;
|
26
26
|
fetchCart(cartId: number): Promise<JourneyCart>;
|
27
27
|
/**
|
@@ -88,3 +88,6 @@ export declare class JourneyBooking extends Booking {
|
|
88
88
|
*/
|
89
89
|
changeSeatsOfTrip(tripId: number, newSeatsIds: number[]): Promise<ErrorResponse | any>;
|
90
90
|
}
|
91
|
+
export declare namespace JourneyBooking {
|
92
|
+
const createBooking: (env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug: boolean, language: string, access_token?: string, sellerId?: number, resellerId?: number) => Promise<JourneyBooking>;
|
93
|
+
}
|
@@ -74,9 +74,10 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
74
74
|
var _this =
|
75
75
|
// Call Booking constructor
|
76
76
|
_super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.MLP, debug, language, access_token, sellerId, resellerId) || this;
|
77
|
+
// Set cartId
|
77
78
|
var cartId = localStorage.getItem("cartId");
|
78
79
|
if (cartId) {
|
79
|
-
_this.
|
80
|
+
_this.cartId = parseInt(cartId);
|
80
81
|
}
|
81
82
|
return _this;
|
82
83
|
}
|
@@ -87,24 +88,28 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
87
88
|
return __awaiter(this, void 0, void 0, function () {
|
88
89
|
var _this = this;
|
89
90
|
return __generator(this, function (_a) {
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
91
|
+
switch (_a.label) {
|
92
|
+
case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (cart) {
|
93
|
+
var cartDate = new Date(cart.bookingDueDate);
|
94
|
+
if (cartDate > new Date()) {
|
95
|
+
_this.cart = cart;
|
96
|
+
_this.cartId = cart.id;
|
97
|
+
_this.bookingDueDate = cartDate; // See Booking class
|
98
|
+
// Fill the booking process status
|
99
|
+
_this.bookingStepsToStatus = new Map(Object.entries(cart.stepsToStatus).map(function (_a) {
|
100
|
+
var bookingStep = _a[0], values = _a[1];
|
101
|
+
return [
|
102
|
+
bookingStep,
|
103
|
+
values
|
104
|
+
];
|
105
|
+
}));
|
106
|
+
_this.createCartTimer(cartDate);
|
107
|
+
}
|
108
|
+
})];
|
109
|
+
case 1:
|
110
|
+
_a.sent();
|
111
|
+
return [2 /*return*/];
|
112
|
+
}
|
108
113
|
});
|
109
114
|
});
|
110
115
|
};
|
@@ -418,3 +423,26 @@ var JourneyBooking = /** @class */ (function (_super) {
|
|
418
423
|
return JourneyBooking;
|
419
424
|
}(booking_1.Booking));
|
420
425
|
exports.JourneyBooking = JourneyBooking;
|
426
|
+
(function (JourneyBooking) {
|
427
|
+
var _this = this;
|
428
|
+
JourneyBooking.createBooking = function (env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
|
429
|
+
var booking, error_1;
|
430
|
+
return __generator(this, function (_a) {
|
431
|
+
switch (_a.label) {
|
432
|
+
case 0:
|
433
|
+
_a.trys.push([0, 3, , 4]);
|
434
|
+
booking = new JourneyBooking(env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId);
|
435
|
+
if (!booking.cartId) return [3 /*break*/, 2];
|
436
|
+
return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
|
437
|
+
case 1:
|
438
|
+
_a.sent();
|
439
|
+
_a.label = 2;
|
440
|
+
case 2: return [2 /*return*/, booking];
|
441
|
+
case 3:
|
442
|
+
error_1 = _a.sent();
|
443
|
+
throw new Error("Could not instantiate JourneyBooking");
|
444
|
+
case 4: return [2 /*return*/];
|
445
|
+
}
|
446
|
+
});
|
447
|
+
}); };
|
448
|
+
})(JourneyBooking || (exports.JourneyBooking = JourneyBooking = {}));
|
@@ -19,7 +19,7 @@ export declare class ServiceBooking extends Booking {
|
|
19
19
|
*/
|
20
20
|
constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
|
21
21
|
getCart(): ServiceCart | undefined;
|
22
|
-
|
22
|
+
fetchAndSetCart(cartId: number): Promise<void>;
|
23
23
|
private createCartTimer;
|
24
24
|
fetchCart(cartId: number): Promise<ServiceCart>;
|
25
25
|
/**
|
@@ -47,3 +47,6 @@ export declare class ServiceBooking extends Booking {
|
|
47
47
|
getServiceTrips(serviceId: number, date: Date): Promise<ErrorResponse | ServiceTrip[]>;
|
48
48
|
createServiceCart(serviceCart: CreateServiceCartRequest): Promise<ErrorResponse | ServiceCart>;
|
49
49
|
}
|
50
|
+
export declare namespace ServiceBooking {
|
51
|
+
const createBooking: (env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug: boolean, language: string, access_token?: string, sellerId?: number, resellerId?: number) => Promise<ServiceBooking>;
|
52
|
+
}
|
@@ -85,9 +85,10 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
85
85
|
var _this =
|
86
86
|
// Call Booking constructor
|
87
87
|
_super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.SERVICE, debug, language, access_token, sellerId, resellerId) || this;
|
88
|
+
// Set cartId
|
88
89
|
var cartId = localStorage.getItem("cartId");
|
89
90
|
if (cartId) {
|
90
|
-
_this.
|
91
|
+
_this.cartId = parseInt(cartId);
|
91
92
|
}
|
92
93
|
return _this;
|
93
94
|
}
|
@@ -98,24 +99,28 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
98
99
|
return __awaiter(this, void 0, void 0, function () {
|
99
100
|
var _this = this;
|
100
101
|
return __generator(this, function (_a) {
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
102
|
+
switch (_a.label) {
|
103
|
+
case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (cart) {
|
104
|
+
var cartDate = new Date(cart.bookingDueDate);
|
105
|
+
if (cartDate > new Date()) {
|
106
|
+
_this.cart = cart;
|
107
|
+
_this.cartId = cart.id;
|
108
|
+
_this.bookingDueDate = cartDate; // See Booking class
|
109
|
+
// Fill the booking process status
|
110
|
+
_this.bookingStepsToStatus = new Map(Object.entries(cart.stepsToStatus).map(function (_a) {
|
111
|
+
var bookingStep = _a[0], values = _a[1];
|
112
|
+
return [
|
113
|
+
bookingStep,
|
114
|
+
values
|
115
|
+
];
|
116
|
+
}));
|
117
|
+
_this.createCartTimer(cartDate);
|
118
|
+
}
|
119
|
+
})];
|
120
|
+
case 1:
|
121
|
+
_a.sent();
|
122
|
+
return [2 /*return*/];
|
123
|
+
}
|
119
124
|
});
|
120
125
|
});
|
121
126
|
};
|
@@ -239,3 +244,26 @@ var ServiceBooking = /** @class */ (function (_super) {
|
|
239
244
|
return ServiceBooking;
|
240
245
|
}(booking_1.Booking));
|
241
246
|
exports.ServiceBooking = ServiceBooking;
|
247
|
+
(function (ServiceBooking) {
|
248
|
+
var _this = this;
|
249
|
+
ServiceBooking.createBooking = function (env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
|
250
|
+
var booking, error_1;
|
251
|
+
return __generator(this, function (_a) {
|
252
|
+
switch (_a.label) {
|
253
|
+
case 0:
|
254
|
+
_a.trys.push([0, 3, , 4]);
|
255
|
+
booking = new ServiceBooking(env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId);
|
256
|
+
if (!booking.cartId) return [3 /*break*/, 2];
|
257
|
+
return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
|
258
|
+
case 1:
|
259
|
+
_a.sent();
|
260
|
+
_a.label = 2;
|
261
|
+
case 2: return [2 /*return*/, booking];
|
262
|
+
case 3:
|
263
|
+
error_1 = _a.sent();
|
264
|
+
throw new Error("Could not instantiate ServiceBooking");
|
265
|
+
case 4: return [2 /*return*/];
|
266
|
+
}
|
267
|
+
});
|
268
|
+
}); };
|
269
|
+
})(ServiceBooking || (exports.ServiceBooking = ServiceBooking = {}));
|
@@ -22,7 +22,7 @@ export declare class SubscriptionBooking extends Booking {
|
|
22
22
|
*/
|
23
23
|
constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug?: boolean, language?: string, access_token?: string, sellerId?: number, resellerId?: number);
|
24
24
|
getCart(): Cart | undefined;
|
25
|
-
|
25
|
+
fetchAndSetCart(cartId: number): Promise<void>;
|
26
26
|
private createCartTimer;
|
27
27
|
fetchCart(cartId: number): Promise<Cart>;
|
28
28
|
/**
|
@@ -90,6 +90,7 @@ export declare class SubscriptionBooking extends Booking {
|
|
90
90
|
updateBuyerPassengersDetails(passengersDetails: EditPassengersDetailsRequest): Promise<ErrorResponse | any>;
|
91
91
|
}
|
92
92
|
export declare namespace SubscriptionBooking {
|
93
|
+
const createBooking: (env: MTSEnvs, sub_key: string, onCartExpiration: () => void, debug: boolean, language: string, access_token?: string, sellerId?: number, resellerId?: number) => Promise<SubscriptionBooking>;
|
93
94
|
enum ValidityTypes {
|
94
95
|
WORKING_WEEK = "WORKING_WEEK",
|
95
96
|
WEEKLY = "WEEKLY",
|
@@ -74,9 +74,10 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
74
74
|
var _this =
|
75
75
|
// Call Booking constructor
|
76
76
|
_super.call(this, env, sub_key, onCartExpiration, booking_1.Booking.BookingTypes.MLP_SUBSCRIPTION, debug, language, access_token, sellerId, resellerId) || this;
|
77
|
+
// Set cartId
|
77
78
|
var cartId = localStorage.getItem("cartId");
|
78
79
|
if (cartId) {
|
79
|
-
_this.
|
80
|
+
_this.cartId = parseInt(cartId);
|
80
81
|
}
|
81
82
|
return _this;
|
82
83
|
}
|
@@ -87,24 +88,28 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
87
88
|
return __awaiter(this, void 0, void 0, function () {
|
88
89
|
var _this = this;
|
89
90
|
return __generator(this, function (_a) {
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
91
|
+
switch (_a.label) {
|
92
|
+
case 0: return [4 /*yield*/, this.fetchCart(cartId).then(function (cart) {
|
93
|
+
var cartDate = new Date(cart.bookingDueDate);
|
94
|
+
if (cartDate > new Date()) {
|
95
|
+
_this.cart = cart;
|
96
|
+
_this.cartId = cart.id;
|
97
|
+
_this.bookingDueDate = cartDate; // See Booking class
|
98
|
+
// Fill the booking process status
|
99
|
+
_this.bookingStepsToStatus = new Map(Object.entries(cart.stepsToStatus).map(function (_a) {
|
100
|
+
var bookingStep = _a[0], values = _a[1];
|
101
|
+
return [
|
102
|
+
bookingStep,
|
103
|
+
values
|
104
|
+
];
|
105
|
+
}));
|
106
|
+
_this.createCartTimer(cartDate);
|
107
|
+
}
|
108
|
+
})];
|
109
|
+
case 1:
|
110
|
+
_a.sent();
|
111
|
+
return [2 /*return*/];
|
112
|
+
}
|
108
113
|
});
|
109
114
|
});
|
110
115
|
};
|
@@ -387,6 +392,27 @@ var SubscriptionBooking = /** @class */ (function (_super) {
|
|
387
392
|
}(booking_1.Booking));
|
388
393
|
exports.SubscriptionBooking = SubscriptionBooking;
|
389
394
|
(function (SubscriptionBooking) {
|
395
|
+
var _this = this;
|
396
|
+
SubscriptionBooking.createBooking = function (env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId) { return __awaiter(_this, void 0, void 0, function () {
|
397
|
+
var booking, error_1;
|
398
|
+
return __generator(this, function (_a) {
|
399
|
+
switch (_a.label) {
|
400
|
+
case 0:
|
401
|
+
_a.trys.push([0, 3, , 4]);
|
402
|
+
booking = new SubscriptionBooking(env, sub_key, onCartExpiration, debug, language, access_token, sellerId, resellerId);
|
403
|
+
if (!booking.cartId) return [3 /*break*/, 2];
|
404
|
+
return [4 /*yield*/, booking.fetchAndSetCart(booking.cartId)];
|
405
|
+
case 1:
|
406
|
+
_a.sent();
|
407
|
+
_a.label = 2;
|
408
|
+
case 2: return [2 /*return*/, booking];
|
409
|
+
case 3:
|
410
|
+
error_1 = _a.sent();
|
411
|
+
throw new Error("Could not instantiate SubscriptionBooking");
|
412
|
+
case 4: return [2 /*return*/];
|
413
|
+
}
|
414
|
+
});
|
415
|
+
}); };
|
390
416
|
var ValidityTypes;
|
391
417
|
(function (ValidityTypes) {
|
392
418
|
ValidityTypes["WORKING_WEEK"] = "WORKING_WEEK";
|
@@ -19,18 +19,28 @@ export type Person = {
|
|
19
19
|
};
|
20
20
|
export declare const DEFAULT_PERSON: Person;
|
21
21
|
export declare const initializePerson: (person?: Person | undefined | null) => Person;
|
22
|
+
/**
|
23
|
+
* @description Represents a passenger in the response of the {@link getPassengersDetails} method. This type extends the {@link Person} type
|
24
|
+
* with the `outboundTariffs` and `returnTariffs` properties.
|
25
|
+
*
|
26
|
+
* @property { Map<number, PassengerTariff>} outboundTariffs - A map containing the outbound tariffs for this passenger. The key is the trip id.
|
27
|
+
* 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
|
28
|
+
* the tariff for the passenger.
|
29
|
+
* @property { Map<number, PassengerTariff>} returnTariffs - Same of `outboundTariffs`, but for the return trip.
|
30
|
+
*/
|
31
|
+
export type GetPassenger = Person & {
|
32
|
+
outboundTariffs: Map<number, PassengerTariff[]>;
|
33
|
+
returnTariffs: Map<number, PassengerTariff[]>;
|
34
|
+
};
|
22
35
|
/**
|
23
36
|
* @description Represents the response of the {@link getBuyerPassengersDetails} method.
|
24
37
|
*
|
25
38
|
* @property {Person} buyer - The {@link Person} object representing the buyer.
|
26
|
-
* @property {
|
27
|
-
* @property {Map<number, PassengerTariff>} tariffs - A map from the trip id to the {@link PassengerTariff} object,
|
28
|
-
* representing the available tariffs for that trip (from the ones chosen by the user when creating the cart).
|
39
|
+
* @property {GetPassenger[]} passengers - An array of {@link GetPassenger} objects representing the passengers.
|
29
40
|
*/
|
30
41
|
export type GetBuyerPassengersDetailsResponse = {
|
31
42
|
buyer: Person;
|
32
|
-
passengers:
|
33
|
-
tariffs: Map<number, PassengerTariff>;
|
43
|
+
passengers: GetPassenger[];
|
34
44
|
};
|
35
45
|
/**
|
36
46
|
* @description Represents the type of the passengers array in {@link EditPassengersDetailsRequest}.
|