amphora 8.4.2-dev.1 → 8.4.2-dev.9.0

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/.eslintrc CHANGED
@@ -51,6 +51,7 @@
51
51
  "no-trailing-spaces": 2,
52
52
  "no-underscore-dangle": 0,
53
53
  "no-unneeded-ternary": 1,
54
+ "one-var": 2,
54
55
  "quotes": [2, "single", "avoid-escape"],
55
56
  "semi": [2, "always"],
56
57
  "keyword-spacing": 2,
package/lib/render.js CHANGED
@@ -123,10 +123,16 @@ function renderPage(uri, req, res, hrStart) {
123
123
  locals.query = req.query;
124
124
  locals.extension = extension;
125
125
 
126
+ log('INFO', '====INSIDE RENDER PAGE', { url: _.get(res, 'locals.url'), hostname: req.hostname });
127
+
126
128
  // look up page alias' component instance
127
129
  return getDBObject(uri)
128
- .then(formDataFromLayout(locals, uri))
130
+ .then(() => {
131
+ log('INFO', '====getdboject RESPONSE', { uri });
132
+ return formDataFromLayout(locals, uri)
133
+ })
129
134
  .then(data => {
135
+ log('INFO', '====formDataFromLayout RESPONSE', { data });
130
136
  logTime(hrStart, uri);
131
137
  return data;
132
138
  })
package/lib/responses.js CHANGED
@@ -364,6 +364,7 @@ function explicitError(err, res) {
364
364
  */
365
365
  function handleError(res) {
366
366
  return function (err) {
367
+ log('INFO', '====handleError function RESPONSE', { res, err });
367
368
  if (err.status && err.name !== 'NotFoundError') {
368
369
  // If we're in this block, the error has a defined `status` property and
369
370
  // the error should be directed out immediately
@@ -445,54 +446,6 @@ function expectJSON(fn, res) {
445
446
  }).catch(handleError(res));
446
447
  }
447
448
 
448
- /**
449
- * Checks the page size requested to make sure it's a Number and within the maximum.
450
- * Returns the default or 0 if there's no default or size is not a Number.
451
- * @param {Object} req
452
- * @returns {number}
453
- */
454
- function checkPageSize(req) {
455
- // Casts value to a number > 0 or undefined.
456
- const toInt = (n) => Math.floor(Math.abs(Number(n))) || undefined;
457
-
458
- const sizeDefault = toInt(process.env.CLAY_STORAGE_DEFAULT_PAGE_SIZE);
459
- const sizeParam = toInt(req.query.size);
460
- const sizeMax = toInt(process.env.CLAY_STORAGE_MAX_PAGE_SIZE);
461
-
462
- console.log(
463
- `env.default ${
464
- process.env.CLAY_STORAGE_DEFAULT_PAGE_SIZE
465
- }, type ${typeof process.env
466
- .CLAY_STORAGE_DEFAULT_PAGE_SIZE}, resolved default ${sizeDefault}, type ${typeof sizeDefault}, resolvedMax ${sizeMax}, query param ${sizeParam}`
467
- );
468
-
469
- const size = sizeParam || sizeDefault;
470
-
471
- if (size) {
472
- return Math.min(sizeMax, size) || size;
473
- }
474
-
475
- return sizeMax;
476
- }
477
-
478
- /**
479
- * Checks whether the previous value for a page request matches up with the uri,
480
- * ie. all the ids returned should contain the request uri.
481
- * @param {Object} req
482
- * @param {Object} res
483
- * @returns {string|undefined}
484
- */
485
- function checkPrevious(req, res) {
486
- const prefix = req.uri;
487
- const previous = req.query.prev;
488
-
489
- if (previous && prefix && !previous.includes(prefix)) {
490
- return handleError(res)(Error('Client: Invalid previous'));
491
- }
492
-
493
- return previous;
494
- }
495
-
496
449
  /**
497
450
  * List all things in the db
498
451
  * @param {object} [options]
@@ -506,9 +459,7 @@ function list(options) {
506
459
  let list,
507
460
  listOptions = _.assign({
508
461
  prefix: req.uri,
509
- values: false,
510
- previous: checkPrevious(req, res),
511
- size: checkPageSize(req)
462
+ values: false
512
463
  }, options);
513
464
 
514
465
  list = db.list(listOptions);
@@ -528,7 +479,7 @@ function listWithoutVersions() {
528
479
  return [filter({wantStrings: true}, function (str) {
529
480
  return str.indexOf('@') === -1;
530
481
  })];
531
- },
482
+ }
532
483
  };
533
484
 
534
485
  return list(options);
@@ -653,5 +604,3 @@ module.exports.deleteRouteFromDB = deleteRouteFromDB;
653
604
  // For testing
654
605
  module.exports.setLog = mock => log = mock;
655
606
  module.exports.setDb = mock => db = mock;
656
- module.exports.checkPrevious = checkPrevious;
657
- module.exports.checkPageSize = checkPageSize;
@@ -314,124 +314,6 @@ describe(_.startCase(filename), function () {
314
314
  });
315
315
  });
316
316
 
317
- describe('checkPageSize', function () {
318
- const fn = lib[this.title];
319
-
320
- afterEach(function () {
321
- delete process.env.CLAY_STORAGE_DEFAULT_PAGE_SIZE;
322
- delete process.env.CLAY_STORAGE_MAX_PAGE_SIZE;
323
- });
324
-
325
- it('falls back to default if there is no size param', function () {
326
- const req = {
327
- query: {},
328
- uri: 'domain.com/_components/component/instances',
329
- };
330
-
331
- const res = createMockRes();
332
-
333
- process.env.CLAY_STORAGE_DEFAULT_PAGE_SIZE = '10';
334
-
335
- expect(fn(req, res)).to.equal(10);
336
- });
337
-
338
- it('returns max when max is defined and size > max', function () {
339
- const req = {
340
- query: { size: '300' },
341
- uri: 'domain.com/_components/component/instances',
342
- };
343
-
344
- const res = createMockRes();
345
-
346
- process.env.CLAY_STORAGE_DEFAULT_PAGE_SIZE = '10';
347
- process.env.CLAY_STORAGE_MAX_PAGE_SIZE = '100';
348
-
349
- expect(fn(req, res)).to.equal(100);
350
- });
351
-
352
- it('returns valid size that is smaller than max', function () {
353
- const req = {
354
- query: { size: '42' },
355
- uri: 'domain.com/_components/component/instances',
356
- };
357
-
358
- const res = createMockRes();
359
-
360
- process.env.CLAY_STORAGE_DEFAULT_PAGE_SIZE = '10';
361
- process.env.CLAY_STORAGE_MAX_PAGE_SIZE = '100';
362
-
363
- expect(fn(req, res)).to.equal(42);
364
- });
365
-
366
- it('returns default for an invalid size query param', function () {
367
- const req = {
368
- query: { size: 'string' },
369
- uri: 'domain.com/_components/component/instances',
370
- };
371
-
372
- const res = createMockRes();
373
-
374
- process.env.CLAY_STORAGE_DEFAULT_PAGE_SIZE = '10';
375
- process.env.CLAY_STORAGE_MAX_PAGE_SIZE = '100';
376
-
377
- expect(fn(req, res)).to.equal(10);
378
- });
379
-
380
- it('returns max when no size or default', function () {
381
- const req = {
382
- query: {},
383
- uri: 'domain.com/_components/component/instances',
384
- };
385
-
386
- const res = createMockRes();
387
-
388
- process.env.CLAY_STORAGE_MAX_PAGE_SIZE = '100';
389
-
390
- expect(fn(req, res)).to.equal(100);
391
- });
392
- });
393
-
394
- describe('checkPrevious', function () {
395
- const fn = lib[this.title];
396
-
397
- it('returns valid previous query param value', function () {
398
- const req = {
399
- query: {
400
- prev: 'domain.com/_components/component/instances/aaa',
401
- },
402
- uri: 'domain.com/_components/component/instances',
403
- };
404
- const res = createMockRes();
405
-
406
- expect(fn(req, res)).to.equal(
407
- 'domain.com/_components/component/instances/aaa'
408
- );
409
- });
410
-
411
- it('throws and responds with 400 for an invalid previous value', function () {
412
- const req = {
413
- query: {
414
- prev: 'random value',
415
- },
416
- uri: 'domain.com/_components/component/instances',
417
- };
418
- const res = createMockRes();
419
-
420
- expectStatus(res, 400);
421
- fn(req, res);
422
- });
423
-
424
- it('returns undefined if no previous value', function () {
425
- const req = {
426
- query: {},
427
- uri: 'domain.com/_components/component/instances',
428
- };
429
- const res = createMockRes();
430
-
431
- expect(fn(req, res)).to.equal(undefined);
432
- });
433
- });
434
-
435
317
  describe('list', function () {
436
318
  const fn = lib[this.title];
437
319
 
package/lib/routes.js CHANGED
@@ -62,23 +62,28 @@ function addUri(req, res, next) {
62
62
  * @param {express.Router} router
63
63
  */
64
64
  function addControllerRoutes(router) {
65
- // load all controller routers
66
- _.each(reservedRoutes, routeName => {
67
- let pathRouter,
68
- filename = routeName + '.js',
69
- controller = files.tryRequire([__dirname, routesPath, filename].join(path.sep));
65
+ try {
66
+ // load all controller routers
67
+ _.each(reservedRoutes, routeName => {
68
+ log('info', 'SETTING RESERVED ROUTES', { reservedRouteName: routeName });
69
+ let pathRouter,
70
+ filename = routeName + '.js',
71
+ controller = files.tryRequire([__dirname, routesPath, filename].join(path.sep));
70
72
 
71
- // we're okay with an error occurring here because it means we're missing something important in a route
72
- pathRouter = express.Router();
73
+ // we're okay with an error occurring here because it means we're missing something important in a route
74
+ pathRouter = express.Router();
73
75
 
74
- // assume json or text for anything in request bodies
75
- pathRouter.use(require('body-parser').json({ strict: true, type: 'application/json', limit: '50mb' }));
76
- pathRouter.use(require('body-parser').text({ type: 'text/*' }));
76
+ // assume json or text for anything in request bodies
77
+ pathRouter.use(require('body-parser').json({ strict: true, type: 'application/json', limit: '50mb' }));
78
+ pathRouter.use(require('body-parser').text({ type: 'text/*' }));
77
79
 
78
- controller(pathRouter);
80
+ controller(pathRouter);
79
81
 
80
- router.use(`/${routeName}`, pathRouter);
81
- });
82
+ router.use(`/${routeName}`, pathRouter);
83
+ });
84
+ } catch (error) {
85
+ log('error', 'CATCH CONTROLLER ROUTES', { error });
86
+ }
82
87
  }
83
88
 
84
89
  /**
@@ -122,6 +127,7 @@ function addCORS(site) {
122
127
  }
123
128
 
124
129
  function setRoutes(controller, router, site) {
130
+ log('info', 'SET ROUTES: ', { site });
125
131
  if (_.isFunction(controller.legacyController)) {
126
132
  controller.legacyController(router, render, site);
127
133
  }
package/lib/setup.js CHANGED
@@ -42,6 +42,8 @@ module.exports = function (options = {}) {
42
42
  eventBus = false
43
43
  } = options, router;
44
44
 
45
+ log('info', 'Testing logs setup line 45');
46
+
45
47
  if (sessionStore) {
46
48
  log('warn', 'Support for sessionStore will be dropped in Amphora v8');
47
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "amphora",
3
- "version": "8.4.2-dev.1",
3
+ "version": "8.4.2-dev.9.0",
4
4
  "description": "An API mixin for Express that saves, publishes and composes data with the key-value store of your choice.",
5
5
  "main": "index.js",
6
6
  "scripts": {