ti2 1.0.56 → 1.0.58
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/controllers/allotment.js +2 -0
- package/controllers/app.js +2 -0
- package/controllers/bookings.js +29 -1
- package/index.js +75 -1
- package/package.json +3 -1
package/controllers/allotment.js
CHANGED
|
@@ -4,6 +4,7 @@ const { UserAppKey } = require('../models/index');
|
|
|
4
4
|
|
|
5
5
|
const queryAllotment = plugins => async (req, res, next) => {
|
|
6
6
|
const {
|
|
7
|
+
axios,
|
|
7
8
|
params: {
|
|
8
9
|
appKey,
|
|
9
10
|
hint,
|
|
@@ -25,6 +26,7 @@ const queryAllotment = plugins => async (req, res, next) => {
|
|
|
25
26
|
const token = await userAppKeys.token;
|
|
26
27
|
assert(app.queryAllotment, 'could not find the allotment method');
|
|
27
28
|
const results = await app.queryAllotment({
|
|
29
|
+
axios,
|
|
28
30
|
token,
|
|
29
31
|
payload: query,
|
|
30
32
|
requestId: req.requestId,
|
package/controllers/app.js
CHANGED
|
@@ -167,6 +167,7 @@ const deleteAppToken = async (req, res, next) => {
|
|
|
167
167
|
|
|
168
168
|
const validateAppToken = plugins => async (req, res, next) => {
|
|
169
169
|
const {
|
|
170
|
+
axios,
|
|
170
171
|
body: {
|
|
171
172
|
tokenHint: hint,
|
|
172
173
|
},
|
|
@@ -189,6 +190,7 @@ const validateAppToken = plugins => async (req, res, next) => {
|
|
|
189
190
|
const token = await userAppKeys.token;
|
|
190
191
|
assert(app.validateToken, `could not find the validateToken method for ${appKey}`);
|
|
191
192
|
const valid = await app.validateToken({
|
|
193
|
+
axios,
|
|
192
194
|
token,
|
|
193
195
|
requestId: req.requestId,
|
|
194
196
|
});
|
package/controllers/bookings.js
CHANGED
|
@@ -22,6 +22,7 @@ const typeDefsAndQueries = {
|
|
|
22
22
|
|
|
23
23
|
const bookingsSearch = plugins => async (req, res, next) => {
|
|
24
24
|
const {
|
|
25
|
+
axios,
|
|
25
26
|
params: { appKey, userId, hint },
|
|
26
27
|
body,
|
|
27
28
|
} = req;
|
|
@@ -38,6 +39,7 @@ const bookingsSearch = plugins => async (req, res, next) => {
|
|
|
38
39
|
const token = await userAppKeys.token;
|
|
39
40
|
const search = (app.searchHotelBooking || app.searchBooking).bind(app);
|
|
40
41
|
const results = await search({
|
|
42
|
+
axios,
|
|
41
43
|
token,
|
|
42
44
|
payload: body,
|
|
43
45
|
typeDefsAndQueries,
|
|
@@ -51,6 +53,7 @@ const bookingsSearch = plugins => async (req, res, next) => {
|
|
|
51
53
|
|
|
52
54
|
const bookingsCancel = plugins => async (req, res, next) => {
|
|
53
55
|
const {
|
|
56
|
+
axios,
|
|
54
57
|
params: { appKey, userId, hint },
|
|
55
58
|
body,
|
|
56
59
|
} = req;
|
|
@@ -67,6 +70,7 @@ const bookingsCancel = plugins => async (req, res, next) => {
|
|
|
67
70
|
assert(userAppKeys, 'could not find the app key');
|
|
68
71
|
const token = await userAppKeys.token;
|
|
69
72
|
const results = await app.cancelBooking({
|
|
73
|
+
axios,
|
|
70
74
|
token,
|
|
71
75
|
payload: body,
|
|
72
76
|
typeDefsAndQueries,
|
|
@@ -79,6 +83,7 @@ const bookingsCancel = plugins => async (req, res, next) => {
|
|
|
79
83
|
};
|
|
80
84
|
|
|
81
85
|
const $bookingsProductSearch = plugins => async ({
|
|
86
|
+
axios,
|
|
82
87
|
appKey,
|
|
83
88
|
userId,
|
|
84
89
|
hint,
|
|
@@ -97,6 +102,7 @@ const $bookingsProductSearch = plugins => async ({
|
|
|
97
102
|
assert(userAppKeys, 'could not find the app key');
|
|
98
103
|
const token = await userAppKeys.token;
|
|
99
104
|
const results = await app.searchProducts({
|
|
105
|
+
axios,
|
|
100
106
|
token,
|
|
101
107
|
payload,
|
|
102
108
|
typeDefsAndQueries,
|
|
@@ -107,12 +113,18 @@ const $bookingsProductSearch = plugins => async ({
|
|
|
107
113
|
|
|
108
114
|
const bookingsProductSearch = plugins => async (req, res, next) => {
|
|
109
115
|
const {
|
|
116
|
+
axios,
|
|
110
117
|
params,
|
|
111
118
|
body: payload,
|
|
112
119
|
requestId,
|
|
113
120
|
} = req;
|
|
114
121
|
try {
|
|
115
|
-
return res.json(await $bookingsProductSearch(plugins)({
|
|
122
|
+
return res.json(await $bookingsProductSearch(plugins)({
|
|
123
|
+
axios,
|
|
124
|
+
...params,
|
|
125
|
+
payload,
|
|
126
|
+
requestId,
|
|
127
|
+
}));
|
|
116
128
|
} catch (err) {
|
|
117
129
|
return next(err);
|
|
118
130
|
}
|
|
@@ -120,6 +132,7 @@ const bookingsProductSearch = plugins => async (req, res, next) => {
|
|
|
120
132
|
|
|
121
133
|
const bookingsAvailabilitySearch = plugins => async (req, res, next) => {
|
|
122
134
|
const {
|
|
135
|
+
axios,
|
|
123
136
|
params: { appKey, userId, hint },
|
|
124
137
|
body: payload,
|
|
125
138
|
} = req;
|
|
@@ -136,6 +149,7 @@ const bookingsAvailabilitySearch = plugins => async (req, res, next) => {
|
|
|
136
149
|
assert(userAppKeys, 'could not find the app key');
|
|
137
150
|
const token = await userAppKeys.token;
|
|
138
151
|
const results = await app.searchAvailability({
|
|
152
|
+
axios,
|
|
139
153
|
token,
|
|
140
154
|
payload,
|
|
141
155
|
typeDefsAndQueries,
|
|
@@ -148,6 +162,7 @@ const bookingsAvailabilitySearch = plugins => async (req, res, next) => {
|
|
|
148
162
|
};
|
|
149
163
|
|
|
150
164
|
const $bookingsAvailabilityCalendar = plugins => async ({
|
|
165
|
+
axios,
|
|
151
166
|
appKey,
|
|
152
167
|
userId,
|
|
153
168
|
hint,
|
|
@@ -166,6 +181,7 @@ const $bookingsAvailabilityCalendar = plugins => async ({
|
|
|
166
181
|
assert(userAppKeys, 'could not find the app key');
|
|
167
182
|
const token = await userAppKeys.token;
|
|
168
183
|
return app.availabilityCalendar({
|
|
184
|
+
axios,
|
|
169
185
|
token,
|
|
170
186
|
payload,
|
|
171
187
|
typeDefsAndQueries,
|
|
@@ -175,12 +191,14 @@ const $bookingsAvailabilityCalendar = plugins => async ({
|
|
|
175
191
|
|
|
176
192
|
const bookingsAvailabilityCalendar = plugins => async (req, res, next) => {
|
|
177
193
|
const {
|
|
194
|
+
axios,
|
|
178
195
|
params,
|
|
179
196
|
body: payload,
|
|
180
197
|
requestId,
|
|
181
198
|
} = req;
|
|
182
199
|
try {
|
|
183
200
|
return res.json(await $bookingsAvailabilityCalendar(plugins)({
|
|
201
|
+
axios,
|
|
184
202
|
...params,
|
|
185
203
|
payload,
|
|
186
204
|
requestId,
|
|
@@ -192,6 +210,7 @@ const bookingsAvailabilityCalendar = plugins => async (req, res, next) => {
|
|
|
192
210
|
|
|
193
211
|
const searchQuote = plugins => async (req, res, next) => {
|
|
194
212
|
const {
|
|
213
|
+
axios,
|
|
195
214
|
params: { appKey, userId, hint },
|
|
196
215
|
body: payload,
|
|
197
216
|
} = req;
|
|
@@ -209,6 +228,7 @@ const searchQuote = plugins => async (req, res, next) => {
|
|
|
209
228
|
const token = await userAppKeys.token;
|
|
210
229
|
assert(payload.id, 'the availability id is required');
|
|
211
230
|
const results = await app.searchQuote({
|
|
231
|
+
axios,
|
|
212
232
|
token,
|
|
213
233
|
payload,
|
|
214
234
|
typeDefsAndQueries,
|
|
@@ -222,6 +242,7 @@ const searchQuote = plugins => async (req, res, next) => {
|
|
|
222
242
|
|
|
223
243
|
const createBooking = plugins => async (req, res, next) => {
|
|
224
244
|
const {
|
|
245
|
+
axios,
|
|
225
246
|
params: { appKey, userId, hint },
|
|
226
247
|
body: payload,
|
|
227
248
|
} = req;
|
|
@@ -239,6 +260,7 @@ const createBooking = plugins => async (req, res, next) => {
|
|
|
239
260
|
const token = await userAppKeys.token;
|
|
240
261
|
assert(payload.id, 'the quote id is required');
|
|
241
262
|
const results = await app.createBooking({
|
|
263
|
+
axios,
|
|
242
264
|
token,
|
|
243
265
|
payload,
|
|
244
266
|
typeDefsAndQueries,
|
|
@@ -252,6 +274,7 @@ const createBooking = plugins => async (req, res, next) => {
|
|
|
252
274
|
|
|
253
275
|
const getAffiliateAgents = plugins => async (req, res, next) => {
|
|
254
276
|
const {
|
|
277
|
+
axios,
|
|
255
278
|
params: { appKey, userId, hint },
|
|
256
279
|
body: payload,
|
|
257
280
|
} = req;
|
|
@@ -269,6 +292,7 @@ const getAffiliateAgents = plugins => async (req, res, next) => {
|
|
|
269
292
|
const token = await userAppKeys.token;
|
|
270
293
|
assert(app.getAffiliateAgents, `getAffiliateAgents is not available for ${appKey}`);
|
|
271
294
|
const results = await app.getAffiliateAgents({
|
|
295
|
+
axios,
|
|
272
296
|
token,
|
|
273
297
|
payload,
|
|
274
298
|
requestId: req.requestId,
|
|
@@ -281,6 +305,7 @@ const getAffiliateAgents = plugins => async (req, res, next) => {
|
|
|
281
305
|
|
|
282
306
|
const getAffiliateDesks = plugins => async (req, res, next) => {
|
|
283
307
|
const {
|
|
308
|
+
axios,
|
|
284
309
|
params: { appKey, userId, hint },
|
|
285
310
|
body: payload,
|
|
286
311
|
} = req;
|
|
@@ -298,6 +323,7 @@ const getAffiliateDesks = plugins => async (req, res, next) => {
|
|
|
298
323
|
const token = await userAppKeys.token;
|
|
299
324
|
assert(app.getAffiliateDesks, `getAffiliateDesks is not available for ${appKey}`);
|
|
300
325
|
const results = await app.getAffiliateDesks({
|
|
326
|
+
axios,
|
|
301
327
|
token,
|
|
302
328
|
payload,
|
|
303
329
|
requestId: req.requestId,
|
|
@@ -310,6 +336,7 @@ const getAffiliateDesks = plugins => async (req, res, next) => {
|
|
|
310
336
|
|
|
311
337
|
const getPickupPoints = plugins => async (req, res, next) => {
|
|
312
338
|
const {
|
|
339
|
+
axios,
|
|
313
340
|
params: { appKey, userId, hint },
|
|
314
341
|
body: payload,
|
|
315
342
|
} = req;
|
|
@@ -327,6 +354,7 @@ const getPickupPoints = plugins => async (req, res, next) => {
|
|
|
327
354
|
const token = await userAppKeys.token;
|
|
328
355
|
assert(app.getPickupPoints, `getPickupPoints is not available for ${appKey}`);
|
|
329
356
|
const results = await app.getPickupPoints({
|
|
357
|
+
axios,
|
|
330
358
|
token,
|
|
331
359
|
payload,
|
|
332
360
|
typeDefsAndQueries,
|
package/index.js
CHANGED
|
@@ -12,6 +12,12 @@ const { Op } = require('sequelize');
|
|
|
12
12
|
const R = require('ramda');
|
|
13
13
|
const { v4: uuidv4 } = require('uuid');
|
|
14
14
|
const EventEmitter = require('eventemitter2');
|
|
15
|
+
const axios = require('axios');
|
|
16
|
+
const curlirize = require('axios-curlirize');
|
|
17
|
+
|
|
18
|
+
if (process.env.debug) {
|
|
19
|
+
curlirize(axios);
|
|
20
|
+
}
|
|
15
21
|
|
|
16
22
|
const cacheSettings = {
|
|
17
23
|
'*': [
|
|
@@ -45,6 +51,14 @@ const rebuild = fn => obj =>
|
|
|
45
51
|
|
|
46
52
|
const isNumber = value => !Number.isNaN(Number(value));
|
|
47
53
|
|
|
54
|
+
const axiosSafeRequest = R.pick(['headers', 'method', 'url', 'data']);
|
|
55
|
+
const axiosSafeResponse = response => {
|
|
56
|
+
const retVal = R.pick(['data', 'status', 'statusText', 'headers', 'request', 'config'], response);
|
|
57
|
+
retVal.request = axiosSafeRequest(retVal.request);
|
|
58
|
+
retVal.config = axiosSafeRequest(retVal.config);
|
|
59
|
+
return retVal;
|
|
60
|
+
};
|
|
61
|
+
|
|
48
62
|
module.exports = async ({
|
|
49
63
|
apiDocs = true,
|
|
50
64
|
plugins: pluginsParam = {},
|
|
@@ -66,7 +80,11 @@ module.exports = async ({
|
|
|
66
80
|
const nuName = attr.replace(/_/g, '-').replace(`ti2-${pluginName}-`, '');
|
|
67
81
|
params[nuName] = value;
|
|
68
82
|
});
|
|
69
|
-
const pluginInstance = await new Plugin({
|
|
83
|
+
const pluginInstance = await new Plugin({
|
|
84
|
+
name: pluginName,
|
|
85
|
+
events: ti2Events,
|
|
86
|
+
...params,
|
|
87
|
+
});
|
|
70
88
|
return pluginInstance;
|
|
71
89
|
});
|
|
72
90
|
if (worker) {
|
|
@@ -184,6 +202,62 @@ module.exports = async ({
|
|
|
184
202
|
responseStatusCode: res.statusCode,
|
|
185
203
|
});
|
|
186
204
|
});
|
|
205
|
+
|
|
206
|
+
const axiosPlugin = axios.create({ headers: { requestId: req.requestId } });
|
|
207
|
+
const pluginName = R.pathOr(
|
|
208
|
+
R.pathOr('ti2', ['params', 'app'], body),
|
|
209
|
+
['params', 'appKey'],
|
|
210
|
+
body,
|
|
211
|
+
);
|
|
212
|
+
const userId = R.pathOr(undefined, ['params', 'userId'], body);
|
|
213
|
+
const plugin = plugins.find(({ name }) => name === pluginName);
|
|
214
|
+
const errorPathsAxiosErrors = R.pathOr(() => [], ['errorPathsAxiosErrors'], plugin)();
|
|
215
|
+
const errorPathsAxiosAny = R.pathOr(() => [], ['errorPathsAxiosAny'], plugin)();
|
|
216
|
+
|
|
217
|
+
axiosPlugin.interceptors.request.use(request => {
|
|
218
|
+
ti2Events.emit(`${pluginName}.axios.request`, { ...axiosSafeRequest(request), userId });
|
|
219
|
+
request.headers.common.requestId = req.requestId;
|
|
220
|
+
return request;
|
|
221
|
+
});
|
|
222
|
+
axiosPlugin.interceptors.response.use(response => {
|
|
223
|
+
ti2Events.emit(`${pluginName}.axios.response`, { ...axiosSafeResponse(response), userId });
|
|
224
|
+
if (errorPathsAxiosAny.length > 0) {
|
|
225
|
+
const pathMatch = errorPathsAxiosAny.find(errorPath => R.path(errorPath, response));
|
|
226
|
+
if (pathMatch) {
|
|
227
|
+
const errMsg = R.path(pathMatch, response);
|
|
228
|
+
if (process.env.debug) console.error(`error in ${pluginName}`, errMsg);
|
|
229
|
+
if (ti2Events.events) {
|
|
230
|
+
ti2Events.events.emit(`${pluginName}.axios.error`, {
|
|
231
|
+
response: axiosSafeResponse(response),
|
|
232
|
+
err: errMsg,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
throw new Eror(errMsg);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return response;
|
|
239
|
+
});
|
|
240
|
+
req.axios = async (...args) => axiosPlugin(...args).catch(err => {
|
|
241
|
+
const errMsg = (() => {
|
|
242
|
+
const defaultErr = R.omit(['config'], err.toJSON()); // default error
|
|
243
|
+
if (errorPathsAxiosErrors.length > 0) {
|
|
244
|
+
const pathMatch = errorPathsAxiosErrors.find(errorPath => R.path(errorPath, err));
|
|
245
|
+
if (pathMatch) {
|
|
246
|
+
return R.path(pathMatch, err);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return defaultErr;
|
|
250
|
+
})();
|
|
251
|
+
if (console.env.debug) console.error(`error in ${pluginName}`, args[0], errMsg);
|
|
252
|
+
if (ti2Events.events) {
|
|
253
|
+
ti2Events.events.emit(`${pluginName}.axios.error`, {
|
|
254
|
+
request: args[0],
|
|
255
|
+
err: errMsg,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
throw new Error(errMsg);
|
|
259
|
+
});
|
|
260
|
+
|
|
187
261
|
next();
|
|
188
262
|
});
|
|
189
263
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ti2",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.58",
|
|
4
4
|
"description": "Tourist Industry Exchange (TI2)",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -25,6 +25,8 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://github.com/ti2travel/ti2#readme",
|
|
27
27
|
"dependencies": {
|
|
28
|
+
"axios": "^0.27.2",
|
|
29
|
+
"axios-curlirize": "^1.3.7",
|
|
28
30
|
"bluebird": "^3.7.2",
|
|
29
31
|
"bull": "^4.8.2",
|
|
30
32
|
"commander": "^9.2.0",
|