mts-booking-library 1.0.1 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/config.d.ts +10 -17
- package/lib/config.js +32 -19
- package/lib/index.d.ts +8 -1
- package/lib/index.js +11 -3
- package/lib/types/Journeys/JourneySearch.d.ts +1 -0
- package/lib/types/Journeys/JourneySearch.js +1 -0
- package/lib/utils/apiCall.js +13 -8
- package/package.json +1 -1
- package/lib/types/BusMatrix.d.ts +0 -0
- package/lib/types/BusMatrix.js +0 -1
- package/lib/types/Journey.d.ts +0 -8
- package/lib/types/Journey.js +0 -2
- package/lib/types/JourneySearch.d.ts +0 -9
- package/lib/types/JourneySearch.js +0 -2
- package/lib/types/Stop.d.ts +0 -7
- package/lib/types/Stop.js +0 -2
- package/lib/types/Tour.d.ts +0 -18
- package/lib/types/Tour.js +0 -2
- package/lib/types/Tours.d.ts +0 -0
- package/lib/types/Tours.js +0 -1
- package/lib/types/Trip.d.ts +0 -9
- package/lib/types/Trip.js +0 -2
- package/lib/types/TripSearch.d.ts +0 -9
- package/lib/types/TripSearch.js +0 -2
package/lib/config.d.ts
CHANGED
@@ -1,20 +1,13 @@
|
|
1
|
-
export declare
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
API_ENDPOINT: string;
|
9
|
-
OCP_SUBSCRIPTION_KEY: string;
|
10
|
-
};
|
11
|
-
export declare const getConfig: () => {
|
12
|
-
API_ENDPOINT: string;
|
13
|
-
OCP_SUBSCRIPTION_KEY: string;
|
14
|
-
} | {
|
15
|
-
API_ENDPOINT: string;
|
16
|
-
OCP_SUBSCRIPTION_KEY: string;
|
17
|
-
} | {
|
1
|
+
export declare enum MTSEnvs {
|
2
|
+
DEV = "DEV",
|
3
|
+
STAGING = "STAGING",
|
4
|
+
PROD = "PROD"
|
5
|
+
}
|
6
|
+
export type MTSConfig = {
|
7
|
+
ENV: MTSEnvs;
|
18
8
|
API_ENDPOINT: string;
|
19
9
|
OCP_SUBSCRIPTION_KEY: string;
|
10
|
+
ACCESS_TOKEN: string | undefined;
|
20
11
|
};
|
12
|
+
export declare const setConfig: (env: MTSEnvs, sub_key: string, access_token?: string) => MTSConfig;
|
13
|
+
export declare const getConfig: () => MTSConfig;
|
package/lib/config.js
CHANGED
@@ -1,28 +1,41 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getConfig = exports.setConfig = void 0;
|
3
|
+
exports.getConfig = exports.setConfig = exports.MTSEnvs = void 0;
|
4
|
+
var MTSEnvs;
|
5
|
+
(function (MTSEnvs) {
|
6
|
+
MTSEnvs["DEV"] = "DEV";
|
7
|
+
MTSEnvs["STAGING"] = "STAGING";
|
8
|
+
MTSEnvs["PROD"] = "PROD";
|
9
|
+
})(MTSEnvs || (exports.MTSEnvs = MTSEnvs = {}));
|
4
10
|
var config = {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
stag: {
|
10
|
-
API_ENDPOINT: "https://myticketsolutionapim.azure-api.net/api/stag",
|
11
|
-
OCP_SUBSCRIPTION_KEY: ""
|
12
|
-
},
|
13
|
-
prod: {
|
14
|
-
API_ENDPOINT: "https://myticketsolutionapim.azure-api.net/api/",
|
15
|
-
OCP_SUBSCRIPTION_KEY: ""
|
16
|
-
}
|
11
|
+
ENV: MTSEnvs.PROD,
|
12
|
+
API_ENDPOINT: "https://myticketsolutionapim.azure-api.net/api",
|
13
|
+
OCP_SUBSCRIPTION_KEY: "",
|
14
|
+
ACCESS_TOKEN: undefined
|
17
15
|
};
|
18
|
-
var
|
19
|
-
|
20
|
-
|
21
|
-
config
|
22
|
-
|
16
|
+
var setConfig = function (env, sub_key, access_token) {
|
17
|
+
// First, set the environment
|
18
|
+
config.ENV = env;
|
19
|
+
switch (config.ENV) {
|
20
|
+
case MTSEnvs.DEV:
|
21
|
+
config.API_ENDPOINT = "https://myticketsolutionapim.azure-api.net/api/dev";
|
22
|
+
break;
|
23
|
+
case MTSEnvs.STAGING:
|
24
|
+
config.API_ENDPOINT = "https://myticketsolutionapim.azure-api.net/api/stag";
|
25
|
+
break;
|
26
|
+
case MTSEnvs.PROD:
|
27
|
+
config.API_ENDPOINT = "https://myticketsolutionapim.azure-api.net/api";
|
28
|
+
break;
|
29
|
+
default:
|
30
|
+
throw new Error("Invalid environment");
|
31
|
+
}
|
32
|
+
// Set OCT and access token
|
33
|
+
config.OCP_SUBSCRIPTION_KEY = sub_key;
|
34
|
+
config.ACCESS_TOKEN = access_token;
|
35
|
+
return config;
|
23
36
|
};
|
24
37
|
exports.setConfig = setConfig;
|
25
38
|
var getConfig = function () {
|
26
|
-
return config
|
39
|
+
return config;
|
27
40
|
};
|
28
41
|
exports.getConfig = getConfig;
|
package/lib/index.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import { MTSEnvs } from "./config";
|
1
2
|
import { Cart, TourCart, JourneyCart } from "./types/Cart";
|
2
3
|
import { Details } from "./types/Details";
|
3
4
|
import { Tour, TourTrip } from "./types/Tours/Tour";
|
@@ -16,9 +17,15 @@ export declare class Booking {
|
|
16
17
|
* @param {string} env The environment in which the app is running. Can be "dev", "stag" or "prod"
|
17
18
|
* @param {string} sub_key The subscription key for using the APIs
|
18
19
|
* @param {() => void} onCartExpiration A callback function that will be called when the cart expires
|
20
|
+
* @param {string} [access_token=undefined] The access token for calling MTS APIs
|
19
21
|
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
20
22
|
*/
|
21
|
-
constructor(env:
|
23
|
+
constructor(env: MTSEnvs, sub_key: string, onCartExpiration: () => void, access_token?: string, sellerId?: number);
|
24
|
+
/**
|
25
|
+
* This method allows to renew the access token for calling MTS APIs
|
26
|
+
* @param {string} access_token The new access token
|
27
|
+
*/
|
28
|
+
renewAccessToken(access_token: string): void;
|
22
29
|
getCartStatus(): Booking.CartStatus;
|
23
30
|
getCart(): Cart | undefined;
|
24
31
|
private fetchAndSetCart;
|
package/lib/index.js
CHANGED
@@ -60,18 +60,26 @@ var Booking = /** @class */ (function () {
|
|
60
60
|
* @param {string} env The environment in which the app is running. Can be "dev", "stag" or "prod"
|
61
61
|
* @param {string} sub_key The subscription key for using the APIs
|
62
62
|
* @param {() => void} onCartExpiration A callback function that will be called when the cart expires
|
63
|
+
* @param {string} [access_token=undefined] The access token for calling MTS APIs
|
63
64
|
* @param {number} [sellerId=undefined] The id of the seller. If not set, it will return the results for all sellers
|
64
65
|
*/
|
65
|
-
function Booking(env, sub_key, onCartExpiration, sellerId) {
|
66
|
+
function Booking(env, sub_key, onCartExpiration, access_token, sellerId) {
|
66
67
|
this.cartStatus = Booking.CartStatus.EMPTY;
|
67
68
|
this.sellerId = sellerId || undefined;
|
68
|
-
this.config = (0, config_1.setConfig)(env, sub_key);
|
69
|
+
this.config = (0, config_1.setConfig)(env, sub_key, access_token);
|
69
70
|
this.onCartExpiration = onCartExpiration;
|
70
71
|
var cartId = localStorage.getItem("cartId");
|
71
72
|
if (cartId) {
|
72
73
|
this.fetchAndSetCart(parseInt(cartId));
|
73
74
|
}
|
74
75
|
}
|
76
|
+
/**
|
77
|
+
* This method allows to renew the access token for calling MTS APIs
|
78
|
+
* @param {string} access_token The new access token
|
79
|
+
*/
|
80
|
+
Booking.prototype.renewAccessToken = function (access_token) {
|
81
|
+
(0, config_1.setConfig)(this.config.ENV, this.config.OCP_SUBSCRIPTION_KEY, access_token);
|
82
|
+
};
|
75
83
|
Booking.prototype.getCartStatus = function () {
|
76
84
|
return this.cartStatus;
|
77
85
|
};
|
@@ -237,7 +245,7 @@ var Booking = /** @class */ (function () {
|
|
237
245
|
if (params.departureStopName === undefined || params.destinationStopName === undefined) {
|
238
246
|
throw Error("Fields departureStopName and destinationStopName are required");
|
239
247
|
}
|
240
|
-
url = "".concat(this.config.API_ENDPOINT, "/booking/journeys?").concat(new URLSearchParams(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), { departureStopName: params.departureStopName, destinationStopName: params.destinationStopName, passengersNumber: params.passengersNumber.toString(), date: params.date.toDateString(), currency: params.currency, isRoundtrip: params.isRoundtrip.toString() })));
|
248
|
+
url = "".concat(this.config.API_ENDPOINT, "/booking/journeys?").concat(new URLSearchParams(__assign(__assign({}, (this.sellerId && { sellerId: this.sellerId.toString() })), { departureStopName: params.departureStopName, destinationStopName: params.destinationStopName, passengersNumber: params.passengersNumber.toString(), date: params.date.toDateString(), roundTripDate: params.roundTripDate ? params.roundTripDate.toDateString() : "null", currency: params.currency, isRoundtrip: params.isRoundtrip.toString() })));
|
241
249
|
return [2 /*return*/, (0, apiCall_1.makeGet)(url)];
|
242
250
|
});
|
243
251
|
});
|
@@ -7,6 +7,7 @@ exports.DefaultJourneySearch = {
|
|
7
7
|
destinationStopName: "",
|
8
8
|
passengersNumber: 1,
|
9
9
|
date: new Date(Date.UTC(new Date().getFullYear(), new Date().getMonth(), new Date().getDate(), 0, 1)),
|
10
|
+
roundTripDate: null,
|
10
11
|
currency: __1.Booking.Currencies.EUR,
|
11
12
|
isRoundtrip: false,
|
12
13
|
};
|
package/lib/utils/apiCall.js
CHANGED
@@ -1,4 +1,15 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
3
|
+
__assign = Object.assign || function(t) {
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5
|
+
s = arguments[i];
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
7
|
+
t[p] = s[p];
|
8
|
+
}
|
9
|
+
return t;
|
10
|
+
};
|
11
|
+
return __assign.apply(this, arguments);
|
12
|
+
};
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
@@ -49,10 +60,7 @@ var makeGet = function (url) { return __awaiter(void 0, void 0, void 0, function
|
|
49
60
|
case 0:
|
50
61
|
_a.trys.push([0, 2, , 3]);
|
51
62
|
return [4 /*yield*/, axios_1.default.get(url, {
|
52
|
-
headers: {
|
53
|
-
"Content-Type": "application/json",
|
54
|
-
"Ocp-Apim-Subscription-Key": (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY,
|
55
|
-
},
|
63
|
+
headers: __assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY }, ((0, config_1.getConfig)().ACCESS_TOKEN && { "Authorization": "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })),
|
56
64
|
})];
|
57
65
|
case 1:
|
58
66
|
response = _a.sent();
|
@@ -80,10 +88,7 @@ var makePost = function (url, data) { return __awaiter(void 0, void 0, void 0, f
|
|
80
88
|
case 0:
|
81
89
|
_a.trys.push([0, 2, , 3]);
|
82
90
|
return [4 /*yield*/, axios_1.default.post(url, data, {
|
83
|
-
headers: {
|
84
|
-
"Content-Type": "application/json",
|
85
|
-
"Ocp-Apim-Subscription-Key": (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY,
|
86
|
-
},
|
91
|
+
headers: __assign({ "Content-Type": "application/json", "Ocp-Apim-Subscription-Key": (0, config_1.getConfig)().OCP_SUBSCRIPTION_KEY }, ((0, config_1.getConfig)().ACCESS_TOKEN && { "Authorization": "Bearer ".concat((0, config_1.getConfig)().ACCESS_TOKEN) })),
|
87
92
|
})];
|
88
93
|
case 1:
|
89
94
|
response = _a.sent();
|
package/package.json
CHANGED
package/lib/types/BusMatrix.d.ts
DELETED
File without changes
|
package/lib/types/BusMatrix.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
"use strict";
|
package/lib/types/Journey.d.ts
DELETED
package/lib/types/Journey.js
DELETED
package/lib/types/Stop.d.ts
DELETED
package/lib/types/Stop.js
DELETED
package/lib/types/Tour.d.ts
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
import { Info } from "./Info";
|
2
|
-
import { Line } from "./Line";
|
3
|
-
import { TariffMatrix, TariffType, TermsType } from "./TermsAndTariffs";
|
4
|
-
export type Tour = {
|
5
|
-
id: number;
|
6
|
-
line: Line;
|
7
|
-
info: Info;
|
8
|
-
tariffsMatrix: TariffMatrix;
|
9
|
-
tariffTypes: TariffType[];
|
10
|
-
termsTypes: TermsType[];
|
11
|
-
isDateOptional: boolean;
|
12
|
-
isDateRequired: boolean;
|
13
|
-
isTripMandatory: boolean;
|
14
|
-
};
|
15
|
-
export type TourTrip = {
|
16
|
-
tripId: number;
|
17
|
-
hour: Date;
|
18
|
-
};
|
package/lib/types/Tour.js
DELETED
package/lib/types/Tours.d.ts
DELETED
File without changes
|
package/lib/types/Tours.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
"use strict";
|
package/lib/types/Trip.d.ts
DELETED
package/lib/types/Trip.js
DELETED
package/lib/types/TripSearch.js
DELETED