ti2 1.0.7 → 1.0.11

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.
@@ -22,9 +22,9 @@ const getAppMethods = plugins => async (req, res, next) => {
22
22
  const { params: { appKey } } = req;
23
23
  try {
24
24
  const app = plugins.filter(({ name }) => name === appKey)[0];
25
- // load(appKey);
25
+ const methods = Object.getOwnPropertyNames(app);
26
26
  return res.json({
27
- methods: Object.getOwnPropertyNames(Object.getPrototypeOf(app)),
27
+ methods,
28
28
  });
29
29
  } catch (err) {
30
30
  return next(err);
package/index.js CHANGED
@@ -39,6 +39,7 @@ module.exports = ({
39
39
  });
40
40
  return new Plugin({ name: pluginName, ...params });
41
41
  });
42
+ // console.log({ plugins });
42
43
  const api = {
43
44
  ...pingController,
44
45
  ...adminController,
@@ -46,6 +47,7 @@ module.exports = ({
46
47
  ...userController(plugins),
47
48
  ...bookingsController(plugins),
48
49
  }; // mehthods that should map to the yaml api spec
50
+ app.plugins = plugins;
49
51
  createMiddleware(schema, app, (_err, middleware) => {
50
52
  if (apiDocs) {
51
53
  app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(schema));
@@ -170,4 +172,4 @@ module.exports = ({
170
172
  });
171
173
 
172
174
  return app;
173
- }
175
+ };
@@ -0,0 +1,25 @@
1
+ {
2
+ "tags": {
3
+ "allowUnknownTags": true,
4
+ "dictionaries": ["jsdoc","closure"]
5
+ },
6
+ "source": {
7
+ "include": ["test"],
8
+ "includePattern": ".+\\.js(doc|x)?$",
9
+ "excludePattern": "(^|\\/|\\\\)_"
10
+ },
11
+ "plugins": [
12
+ "plugins/markdown"
13
+ ],
14
+ "templates": {
15
+ "cleverLinks": true,
16
+ "monospaceLinks": true
17
+ },
18
+ "opts": {
19
+ "destination": "docs",
20
+ "recurse": true,
21
+ "sort": false,
22
+ "readme": "README.md",
23
+ "template": "node_modules/minami"
24
+ }
25
+ }
@@ -1,6 +1,3 @@
1
- const assert = require('assert');
2
- const faker = require('faker');
3
-
4
1
  module.exports = {
5
2
  up: async queryInterface => {
6
3
  const payload = {
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "ti2",
3
- "version": "1.0.7",
3
+ "version": "1.0.11",
4
4
  "description": "Tourist Industry Exchange (TI2)",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "test": "jest || echo \"always ok\"",
8
- "sequelize": "sequelize-cli"
7
+ "test": "jest",
8
+ "sequelize": "sequelize-cli",
9
+ "doc": "jsdoc -c jsdoc.conf.json"
9
10
  },
10
11
  "repository": {
11
12
  "type": "git",
@@ -28,9 +29,9 @@
28
29
  "seque": "^1.2.1",
29
30
  "sequelize": "^6.13.0",
30
31
  "sequelize-cli": "^6.4.1",
31
- "swagger-express-middleware": "^3.0.0-alpha.5",
32
- "swagger-routes-express": "^3.3.1",
33
- "swagger-ui-express": "^4.3.0",
32
+ "swagger-express-middleware": "3.0.0-alpha.5",
33
+ "swagger-routes-express": "3.3.1",
34
+ "swagger-ui-express": "4.3.0",
34
35
  "uninstall": "^0.0.0"
35
36
  },
36
37
  "devDependencies": {
@@ -39,6 +40,8 @@
39
40
  "eslint-config-airbnb-base": "^15.0.0",
40
41
  "eslint-plugin-import": "^2.25.4",
41
42
  "jest": "^27.4.7",
43
+ "jsdoc": "^3.6.10",
44
+ "minami": "git+https://github.com/MyNameReallySux/minami.git#sort-data",
42
45
  "supertest": "^6.2.2"
43
46
  }
44
47
  }
File without changes
package/test/plugin.js ADDED
@@ -0,0 +1,415 @@
1
+ /* global jest, expect */
2
+ const chance = require('chance').Chance();
3
+
4
+ class Plugin {
5
+ /**
6
+ * **General** Methods:
7
+ * * [validateToken](#validateToken).
8
+ *
9
+ * **Content Methods**:
10
+ * * [getProfile](#getProfile)
11
+ * * [updateProfile](#updateProfile)
12
+ * * [createLocation](#createLocation)
13
+ * * [updateLocation](#updateLocation)
14
+ * * [getProducts](#getProducts)
15
+ * * [createProduct](#createProduct)
16
+ * * [updateProduct](#updateProduct)
17
+ *
18
+ * **Booking Methods**:
19
+ * * [searchBooking](#searchBooking)
20
+ * * [searchProducts](#searchProducts)
21
+ * * [searchAvailability](#searchAvailability)
22
+ * * [quoteAvailability](#quoteAvailability)
23
+ * * [createBooking](#createBooking)
24
+ * ---
25
+ *
26
+ * @param {Object} args - New / Overwriting attributes for the Plugin.
27
+ */
28
+ constructor(params = {}) {
29
+ Object.entries(params).forEach(([attr, value]) => {
30
+ this[attr] = value;
31
+ });
32
+ // mock implementations
33
+ this.validateToken = jest.fn(() => true);
34
+ this.getProfile = jest.fn(() => {});
35
+ this.updateProfile = jest.fn(() => {});
36
+ this.getProduct = jest.fn(() => ({ products: [] }));
37
+ this.getProducts = jest.fn(() => true);
38
+ this.createLocation = jest.fn(() => ({ locationId: chance.guid() }));
39
+ this.updateLocation = jest.fn(() => true);
40
+ this.searchBooking = jest.fn(() => ({ bookings: [] }));
41
+ this.searchProducts = jest.fn(() => ({ bookings: [], products: [] }));
42
+ this.searchAvailability = jest.fn(({
43
+ token,
44
+ payload: {
45
+ travelDateStart,
46
+ travelDateEnd,
47
+ dateFormat,
48
+ occupancies,
49
+ },
50
+ }) => {
51
+ expect(token).toBeTruthy();
52
+ expect(travelDateStart).toBeTruthy();
53
+ expect(travelDateEnd).toBeTruthy();
54
+ expect(dateFormat).toBeTruthy();
55
+ expect(Array.isArray(occupancies)).toBeTruthy();
56
+ return { availability: [{ id: chance.guid() }] };
57
+ });
58
+
59
+ this.searchQuote = jest.fn(() => ({ quote: [{ id: chance.guid() }] }));
60
+ this.createBooking = jest.fn(() => {});
61
+ }
62
+
63
+ /**
64
+ * Check the vailidity of an integration token. *part of **General** Methods*
65
+ * @async
66
+ * @param {Object} args - Availability search arguments.
67
+ * @param {Object} args.token - A token definition, it's content varies between integrations.
68
+ * @returns {Boolean} - The token vailidity True/False
69
+ */
70
+ validateToken() {
71
+ return Boolean(this);
72
+ }
73
+ /**
74
+ * GPS Location Object
75
+ * @typedef {Object} GPSLocation
76
+ * @property {String} lat - GPS latitude
77
+ * @property {String} lng - GPS Longitude
78
+ */
79
+
80
+ /**
81
+ * Address Object
82
+ * @typedef {Object} Address
83
+ * @property {string} addressOne - Street Address first line of text
84
+ * @property {string} addressTwo - Street Address second line of text
85
+ * @property {string} city - City
86
+ * @property {string} state - State
87
+ * @property {string} zipCode - Zip/Postal Code
88
+ * @property {GPSLocation} loc -Location
89
+ */
90
+
91
+ /**
92
+ * Profile Object
93
+ * @typedef {Object} Profile
94
+ * @property {string} companyName
95
+ * @property {Address} address
96
+ */
97
+
98
+ /**
99
+ * Returns the profile details of the account.
100
+ * @category Methods
101
+ * @subcategory Content
102
+ * Returns the profile details of the account.
103
+ * @async
104
+ * @param {Object} args - Availability search arguments.
105
+ * @param {Object} args.token - A token definition, it's content varies between integrations.
106
+ * @returns {Profile} - The profile details.
107
+ */
108
+ getProfile() {
109
+ return {};
110
+ }
111
+
112
+ /**
113
+ * Updates profile information
114
+ * @async
115
+ * @param {Object} args - Availability search arguments.
116
+ * @param {Profile} args.payload - Updated profile information
117
+ * @returns {boolean} - True/False success status.
118
+ */
119
+ updateProfile() {
120
+ return {};
121
+ }
122
+
123
+ /**
124
+ * Location Object
125
+ * @typedef {Object} Location
126
+ * @property {string} telephone
127
+ * @property {Address} address
128
+ */
129
+
130
+ /**
131
+ * Create a Location
132
+ * @async
133
+ * @param {Object} args - Availability search arguments.
134
+ * @param {Object} args.token - A token definition, it's content varies between integrations.
135
+ * @param {Location} args.payload - The new location details.
136
+ * @returns {Object} retVal - An object containing return values.
137
+ * @returns {string} retVal.locationId - The new location unique identifier.
138
+ */
139
+ createLocation() {
140
+ return { locationId: chance.guid() };
141
+ }
142
+
143
+ /**
144
+ * Update a Location
145
+ * @async
146
+ * @param {Object} args - Availability search arguments.
147
+ * @param {Object} args.token - A token definition, it's content varies between integrations.
148
+ * @param {string} args.locationId - The unique identifier of the location to update.
149
+ * @param {Location} args.payload - The new location details.
150
+ * @returns {boolean} - True/False success status.
151
+ */
152
+ updateLocation() {
153
+ return true;
154
+ }
155
+ /**
156
+ * Media Object
157
+ * @typedef {Object} Media - Media Details
158
+ * @property {string} mediaType - MimeType of media
159
+ * @property {string} url - URL of media
160
+ */
161
+
162
+ /**
163
+ * Media Collection
164
+ * @typedef {Object} MediaCollection - Media Collection, grouped by type
165
+ * @property {Array.Media} image
166
+ * @property {Array.Media} video
167
+ */
168
+
169
+ /**
170
+ * Room Object
171
+ * @typedef {Object} RoomInfo - Room details object
172
+ * @property {number} count - Number of rooms
173
+ * @property {string} bedType - Bedding type
174
+ * @property {string} other - Exta Information
175
+ */
176
+
177
+ /**
178
+ * Value and UUnit spec
179
+ * @typedef {Object} ValueUnit - ValueDetails fields
180
+ * @property {string} unit - A unit specification
181
+ * @property {number} value - The number of units
182
+ */
183
+
184
+ /**
185
+ * Get the product details related to a location
186
+ * @async
187
+ * @param {Object} args - Availability search arguments.
188
+ * @param {Object} args.token - A token definition, it's content varies between integrations.
189
+ * @param {Object} args.locationId - A location unique identifier for the matching product.
190
+ * @param {Object} args.productId - The product unique identifier.
191
+ * @returns {Object} retVal - A return object.
192
+ * @returns {Product} retVal.product - Details of the matching product.
193
+ */
194
+ /**
195
+ * ProductInfo type
196
+ * @typedef ProductInfo
197
+ * @property {string} include
198
+ * @property {string} exclude
199
+ * @property {string} whatToBring
200
+ */
201
+ /**
202
+ * bedsAndSofas type
203
+ * @typedef BedsAndSofas
204
+ * @property {boolean} isApartment
205
+ * @property {numeric} count
206
+ * @property {string} other
207
+ */
208
+ /**
209
+ * Product Object
210
+ * @typedef {Object} Product - Product information Object
211
+ * @property {string} productId - A unique identifier for a product
212
+ * @property {string} productName
213
+ * @property {('accommodation'|'non-accommodation')} productType
214
+ * @property {string} productCode
215
+ * @property {string} description
216
+ * @property {string} notes
217
+ * @property {string} coverImageUrl
218
+ * @property {boolean} interconnectingRooms
219
+ * @property {string} amenities
220
+ * @property {ValueUnit} roomCountInfo
221
+ * @property {MediaCollection} media
222
+ * @property {ValueUnit} roomSizeInfo
223
+ * @property {ValueUnit} tourDuration
224
+ * @property {number} totalMaxPassengers
225
+ * @property {number} totalMinPassengers
226
+ * @property {ValueUnit} totalDuration
227
+ * @property {boolean} tourDurationDoesNotApply
228
+ * @property {ProductInfo} productInfo
229
+ * @property {BedsAndSofas} bedsAndSofas
230
+ */
231
+ getProduct() {
232
+ return {};
233
+ }
234
+
235
+ /**
236
+ * Get the list of products for a given location
237
+ * @async
238
+ * @param {Object} args - Availability search arguments.
239
+ * @param {Object} args.token - A token definition, it's content varies between integrations.
240
+ * @param {Object} args.locationId - A location unique identifier to get the list of products.
241
+ * @returns {Object} retVal - An object containing return values.
242
+ * @returns {Array.Product} retVal.products - An array of matching products.
243
+ */
244
+ getProducts() {
245
+ return { products: [] };
246
+ }
247
+
248
+ /**
249
+ * Create a Product
250
+ * @async
251
+ * @param {Object} args - Availability search arguments.
252
+ * @param {Object} args.token - A token definition, it's content varies between integrations.
253
+ * @param {string} args.locationId - The unique identifier of the location that will contain the product.
254
+ * @param {Product} args.payload - The new product details.
255
+ * @returns {Object} retVal - An object containing return values.
256
+ * @returns {string} retVal.locationId - The new location unique identifier.
257
+ */
258
+ createProduct() {
259
+ return { locationId: chance.guid(), productId: chance.guid() };
260
+ }
261
+
262
+ /**
263
+ * Update a Product
264
+ * @async
265
+ * @param {Object} args - Availability search arguments.
266
+ * @param {Object} args.token - A token definition, it's content varies between integrations.
267
+ * @param {string} args.locationId - The unique identifier of the location that contains the product.
268
+ * @param {string} args.productId - The unique identifier of the product to update.
269
+ * @param {Product} args.payload - The new location details.
270
+ * @returns {boolean} - True/False success status.
271
+ */
272
+ updateProduct() {
273
+ return true;
274
+ }
275
+
276
+ searchHotelBooking = jest.fn(() => ({ bookings: [] }));
277
+
278
+ /**
279
+ * Booking Object
280
+ * @typedef {Object} Booking
281
+ * @property {string} id Booking unique identifier.
282
+ * @property {Cancelled|Active|Pending} status The currrent booking status.
283
+ * @property {Holder} holder Booking holder information.
284
+ * @property {string} telephone Contact telephone.
285
+ * @property {string} supplierId Supplier of the Booking
286
+ * @property {string} hotelId A HotelId if the booking is for an accommodation.
287
+ * @property {string} hotelName A Hotel Name if the booking is for an accommodation.
288
+ * @property {BookingRoom[]} rooms Booking Room details.
289
+ * @property {string} start CheckIn.
290
+ * @property {string} end CheckOut.
291
+ * @property {string} bookingDate Date when the booking was created.
292
+ * @property {numeric} price Total price for the booking.
293
+ * @property {CancelPolicy} cancelPolicy Cancellation policies for the booking.
294
+ */
295
+ /**
296
+ * Booking Room
297
+ * @typedef {Object} BookingRoom
298
+ * @property {string} roomId
299
+ * @property {string} description
300
+ * @property {numeric} price
301
+ */
302
+
303
+ /**
304
+ * Cancel Policy
305
+ * @typedef {Object} CancelPolicy
306
+ * @property {boolean} refundable
307
+ * @property {string} cancelPenalties
308
+ */
309
+
310
+ /**
311
+ * Search for bookings with a criteria.
312
+ * @async
313
+ * @param {Object} args - Booking search arguments.
314
+ * @param {Object} args.token - A token definition, it's content varies between integrations.
315
+ * @param {Object} args.payload - Search criteria object.
316
+ * @param {string} args.payload.bookingId - a Booking Id.
317
+ * @param {string} args.payload.dateFormat - Date format sent, using [momentjs formatting](https://momentjs.com/docs/#/parsing/string-format/).
318
+ * @param {string} args.payload.purchaseDateStart - Date of purchase start.
319
+ * @param {string} args.payload.purchaseDateEnd - Date of purchase end.
320
+ * @param {string} args.payload.travelDateStart - Date of travel start.
321
+ * @param {string} args.payload.travelDateEnd - Date of travel end.
322
+ * @param {Holder} args.payload.holder - Search for a particular holder.
323
+ * @returns {object} retVal - the return object.
324
+ * @returns {Booking[]} retVal.bookings - Array of Bookings matchin the criteria.
325
+ */
326
+ searchBooking() {
327
+ }
328
+
329
+ /**
330
+ * Search for bookable products
331
+ * @async
332
+ * @param {Object} args - Product search arguments.
333
+ * @param {Object} args.token - A token definition, it's content varies between integrations.
334
+ * @param {Object} args.payload - Search criteria object.
335
+ * @returns {object} retVal - the return object.
336
+ * @returns {Hotel[]} retVal.hotels - Array of bookable hotels.
337
+ * @returns {Product[]} retVal.products - Array of bookable activities.
338
+ * @todo Define search criteria and Hotel/Product spec.
339
+ */
340
+ searchProducts() {
341
+ }
342
+
343
+ /**
344
+ * Occupancy Object
345
+ * @typedef {Object} Occupancy
346
+ * @property {Pax[]} paxes
347
+ */
348
+ /**
349
+ * A Pax item with an age spec.
350
+ * @typedef {Object} Pax
351
+ * @property {number} age Age in years of the pax when the startDate starts on local timezone.
352
+ */
353
+ /**
354
+ * An availability return spec.
355
+ * @typedef {Object} Availability
356
+ * @property {string} id An identifier that can be used to retrieve a quote.
357
+ */
358
+ /**
359
+ * A booking holder spec.
360
+ * @typedef {Object} Holder
361
+ * @property {string} name The booking's holder first name (s).
362
+ * @property {string} surname Surname / Last Name(s) for the booking holder.
363
+ * @property {string} email The booking's holder email.
364
+ */
365
+ /**
366
+ * Search for availability of products winthin dates of travel.
367
+ * @async
368
+ * @param {Object} args - Availability search arguments.
369
+ * @param {Object} args.token - A token definition, it's content varies between integrations.
370
+ * @param {Object} args.payload - Search spect object.
371
+ * @param {string} args.payload.dateFormat - Date format sent, using [momentjs formatting](https://momentjs.com/docs/#/parsing/string-format/).
372
+ * @param {string} args.payload.travelDateStart - Date of travel start.
373
+ * @param {string} args.payload.travelDateEnd - Date of travel end.
374
+ * @param {Occupancy[]} args.payload.occupancies - Occupancy detail.
375
+ * @returns {object} retVal - the return object
376
+ * @returns {Availability[]} retVal.availability - Array of availability objects
377
+ */
378
+ searchAvailability() {
379
+ // return (args);
380
+ }
381
+
382
+ /**
383
+ * A quote return spec
384
+ * @typedef {Object} Quote
385
+ * @property {string} id An identifier that can be used to create a booking.
386
+ */
387
+ /**
388
+ * Quote an availability.
389
+ * @async
390
+ * @param {Object} args - Availability quote arguments.
391
+ * @param {Object} args.token - A token definition, it's content varies between integrations.
392
+ * @param {Object} args.payload - Search spect object.
393
+ * @param {string} args.payload.id - An availability Id.
394
+ * @returns {object} retVal - the return object.
395
+ * @returns {Quote} retVal.quote - A Quote Object instance.
396
+ */
397
+ searchQuote() {
398
+ // return (args);
399
+ }
400
+
401
+ /**
402
+ * Create a Booking
403
+ * @async
404
+ * @param {Object} args - Booking arguments.
405
+ * @param {Object} args.token - A token definition, it's content varies between integrations.
406
+ * @param {Object} args.payload - Search spect object.
407
+ * @param {string} args.payload.id - A quote id.
408
+ * @param {Holder} args.payload.holder - Contact information of the booking holder.
409
+ * @returns {object} retVal - the return object.
410
+ * @returns {Booking} retVal.booking - A Booking object.
411
+ */
412
+ createBooking() {}
413
+ }
414
+
415
+ module.exports = Plugin;
@@ -0,0 +1,21 @@
1
+ // source : https://gist.github.com/codeguy/6684588
2
+
3
+ const slugify = strParam => {
4
+ let str = strParam.replace(/^\s+|\s+$/g, ''); // trim
5
+ str = str.toLowerCase();
6
+
7
+ // remove accents, swap ñ for n, etc
8
+ const from = 'àáäâèéëêìíïîòóöôùúüûñç·/_,:;';
9
+ const to = 'aaaaeeeeiiiioooouuuunc------';
10
+ for (let i = 0, l = from.length; i < l; i += 1) {
11
+ str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
12
+ }
13
+
14
+ str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
15
+ .replace(/\s+/g, '-') // collapse whitespace and replace by -
16
+ .replace(/-+/g, '-'); // collapse dashes
17
+
18
+ return str;
19
+ };
20
+
21
+ module.exports = slugify;