ti2 1.0.64 → 1.0.65

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/api.yml CHANGED
@@ -1027,6 +1027,77 @@ paths:
1027
1027
  content:
1028
1028
  application/json:
1029
1029
  $ref: '#/components/schemas/Status'
1030
+ /{appKey}/{userId}/affiliates:
1031
+ get:
1032
+ security:
1033
+ - bearerAuth: ['admin', 'user']
1034
+ tags:
1035
+ - bookings
1036
+ summary: Gets all affiliates for this user
1037
+ operationId: getAffiliates
1038
+ parameters:
1039
+ - name: appKey
1040
+ in: path
1041
+ description: name of the app to get the affiliates for (defaults to first token found)
1042
+ required: true
1043
+ example: 'xola'
1044
+ schema:
1045
+ type: string
1046
+ - name: userId
1047
+ in: path
1048
+ description: the user/company that the appKey belongs to
1049
+ required: true
1050
+ schema:
1051
+ type: string
1052
+ responses:
1053
+ '200':
1054
+ description: affiliates
1055
+ content:
1056
+ application/json:
1057
+ schema:
1058
+ type: object
1059
+ properties:
1060
+ affiliates:
1061
+ type: array
1062
+ /{appKey}/{userId}/{hint}/affiliates:
1063
+ get:
1064
+ security:
1065
+ - bearerAuth: ['admin', 'user']
1066
+ tags:
1067
+ - bookings
1068
+ summary: Gets all affiliates for this user
1069
+ operationId: getAffiliates
1070
+ parameters:
1071
+ - name: appKey
1072
+ in: path
1073
+ description: name of the app to get the affiliates for the token using the hint
1074
+ required: true
1075
+ example: 'xola'
1076
+ schema:
1077
+ type: string
1078
+ - name: userId
1079
+ in: path
1080
+ description: the user/company that the appKey belongs to
1081
+ required: true
1082
+ schema:
1083
+ type: string
1084
+ - name: hint
1085
+ in: path
1086
+ description: a specific token hint to be used
1087
+ required: true
1088
+ example: 'xola-helloworld'
1089
+ schema:
1090
+ type: string
1091
+ responses:
1092
+ '200':
1093
+ description: affiliates
1094
+ content:
1095
+ application/json:
1096
+ schema:
1097
+ type: object
1098
+ properties:
1099
+ affiliates:
1100
+ type: array
1030
1101
  /affiliate/{appKey}/{userId}/desks:
1031
1102
  get:
1032
1103
  security:
@@ -1865,6 +1936,78 @@ paths:
1865
1936
  application/json:
1866
1937
  schema:
1867
1938
  $ref: '#/components/schemas/AnyValue'
1939
+ /bookings/{appKey}/{userId}/custom-fields:
1940
+ get:
1941
+ security:
1942
+ - bearerAuth: ['admin', 'user']
1943
+ tags:
1944
+ - bookings
1945
+ summary: Gets all custom fields for creating a booking
1946
+ operationId: getCreateBookingFields
1947
+ parameters:
1948
+ - name: appKey
1949
+ in: path
1950
+ description: name of the app to get the resource for (defaults to first token found)
1951
+ required: true
1952
+ example: 'fareharbor'
1953
+ schema:
1954
+ type: string
1955
+ - name: userId
1956
+ in: path
1957
+ description: the user/company that the appKey belongs to
1958
+ required: true
1959
+ schema:
1960
+ type: string
1961
+ responses:
1962
+ '200':
1963
+ description: fields
1964
+ content:
1965
+ application/json:
1966
+ schema:
1967
+ type: object
1968
+ properties:
1969
+ fields:
1970
+ type: array
1971
+ /bookings/{appKey}/{userId}/{hint}/custom-fields:
1972
+ get:
1973
+ security:
1974
+ - bearerAuth: ['admin', 'user']
1975
+ tags:
1976
+ - bookings
1977
+ summary: Gets all custom fields for creating a booking
1978
+ operationId: getCreateBookingFields
1979
+ parameters:
1980
+ - name: appKey
1981
+ in: path
1982
+ description: name of the app to get the resource for the token using the hint
1983
+ required: true
1984
+ example: 'xola'
1985
+ schema:
1986
+ type: string
1987
+ - name: userId
1988
+ in: path
1989
+ description: the user/company that the appKey belongs to
1990
+ required: true
1991
+ schema:
1992
+ type: string
1993
+ - name: hint
1994
+ in: path
1995
+ description: a specific token hint to be used
1996
+ required: true
1997
+ example: 'xola-helloworld'
1998
+ schema:
1999
+ type: string
2000
+ responses:
2001
+ '200':
2002
+ description: fields
2003
+ content:
2004
+ application/json:
2005
+ schema:
2006
+ type: object
2007
+ properties:
2008
+ fields:
2009
+ type: array
2010
+
1868
2011
  /allotment/{appKey}/{userId}:
1869
2012
  get:
1870
2013
  security:
@@ -200,6 +200,37 @@ const validateAppToken = plugins => async (req, res, next) => {
200
200
  }
201
201
  };
202
202
 
203
+ const getAffiliates = plugins => async (req, res, next) => {
204
+ const {
205
+ axios,
206
+ params: { appKey, userId, hint },
207
+ body: payload,
208
+ } = req;
209
+ try {
210
+ const app = plugins.find(({ name }) => name === appKey);
211
+ assert(app, `could not find the app ${appKey}`);
212
+ const userAppKeys = await sqldb.UserAppKey.findOne({
213
+ where: {
214
+ userId,
215
+ integrationId: appKey,
216
+ ...(hint ? { hint } : {}),
217
+ },
218
+ });
219
+ assert(userAppKeys, 'could not find the app key');
220
+ const token = await userAppKeys.token;
221
+ assert(app.getAffiliates, `could not find the getAffiliates method for ${appKey}`);
222
+ const retVal = await app.getAffiliates({
223
+ axios,
224
+ token,
225
+ requestId: req.requestId,
226
+ payload,
227
+ });
228
+ return res.json(retVal);
229
+ } catch (err) {
230
+ return next(err);
231
+ }
232
+ };
233
+
203
234
  const listAppTokens = async (req, res, next) => {
204
235
  const { params: { app: integrationId } } = req;
205
236
  try {
@@ -428,4 +459,5 @@ module.exports = plugins => ({
428
459
  runAppJob,
429
460
  tokenTemplate,
430
461
  validateAppToken: validateAppToken(plugins),
462
+ getAffiliates: getAffiliates(plugins),
431
463
  });
@@ -365,6 +365,37 @@ const getPickupPoints = plugins => async (req, res, next) => {
365
365
  }
366
366
  };
367
367
 
368
+ const getCreateBookingFields = plugins => async (req, res, next) => {
369
+ const {
370
+ axios,
371
+ params: { appKey, userId, hint },
372
+ body: payload,
373
+ } = req;
374
+ try {
375
+ const app = plugins.find(({ name }) => name === appKey);
376
+ // const app = load(appKey);
377
+ const userAppKeys = (await UserAppKey.findOne({
378
+ where: {
379
+ userId,
380
+ integrationId: appKey,
381
+ ...(hint ? { hint } : {}),
382
+ },
383
+ }));
384
+ assert(userAppKeys, 'could not find the app key');
385
+ const token = await userAppKeys.token;
386
+ assert(app.getCreateBookingFields, `getCreateBookingFields is not available for ${appKey}`);
387
+ const results = await app.getCreateBookingFields({
388
+ axios,
389
+ token,
390
+ payload,
391
+ typeDefsAndQueries,
392
+ });
393
+ return res.json(results);
394
+ } catch (err) {
395
+ return next(err);
396
+ }
397
+ };
398
+
368
399
  module.exports = plugins => ({
369
400
  bookingsSearch: bookingsSearch(plugins),
370
401
  bookingsCancel: bookingsCancel(plugins),
@@ -378,4 +409,5 @@ module.exports = plugins => ({
378
409
  getAffiliateAgents: getAffiliateAgents(plugins),
379
410
  getAffiliateDesks: getAffiliateDesks(plugins),
380
411
  getPickupPoints: getPickupPoints(plugins),
412
+ getCreateBookingFields: getCreateBookingFields(plugins),
381
413
  });
package/index.js CHANGED
@@ -21,6 +21,7 @@ const cacheSettings = {
21
21
  'getAffiliateDesks',
22
22
  'getPickupPoints',
23
23
  'bookingsProductSearch',
24
+ 'getCreateBookingFields',
24
25
  ],
25
26
  ventrata: [],
26
27
  fareharbor: [],
@@ -274,7 +275,7 @@ module.exports = async ({
274
275
  }
275
276
  const realSend = res.json;
276
277
  res.json = newData => { // new res.json
277
- if (res.statusCode === 200) {
278
+ if (res.statusCode === 200 || res.statusCode === 304) {
278
279
  cache.save({
279
280
  pluginName: req.pathParams.appKey,
280
281
  key: cacheKey,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ti2",
3
- "version": "1.0.64",
3
+ "version": "1.0.65",
4
4
  "description": "Tourist Industry Exchange (TI2)",
5
5
  "main": "index.js",
6
6
  "scripts": {