@apolitical/server 3.0.0-beta.1 → 3.0.0-beta.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apolitical/server",
3
- "version": "3.0.0-beta.1",
3
+ "version": "3.0.0-beta.2",
4
4
  "description": "Node.js module to encapsulate Apolitical's express server setup",
5
5
  "author": "Apolitical Group Limited <engineering@apolitical.co>",
6
6
  "license": "MIT",
package/src/config.js CHANGED
@@ -54,9 +54,9 @@ module.exports = {
54
54
  },
55
55
  },
56
56
  MORGAN_OPTIONS: {
57
- LOGGED_OUT_SLUG: 'logged-out',
57
+ LOGGED_OUT_ID: 'logged-out',
58
58
  TOKENS: {
59
- USER_SLUG: 'user-slug',
59
+ USER_ID: 'user-id',
60
60
  },
61
61
  },
62
62
  CACHE_OPTIONS: {
@@ -2,12 +2,12 @@
2
2
 
3
3
  module.exports = ({ morgan, config, logger }) => {
4
4
  const {
5
- LOGGED_OUT_SLUG,
6
- TOKENS: { USER_SLUG },
5
+ LOGGED_OUT_ID,
6
+ TOKENS: { USER_ID },
7
7
  } = config.SERVER.MORGAN_OPTIONS;
8
8
 
9
- function getUserSlug(req) {
10
- return req.user && req.user.slug ? req.user.slug : LOGGED_OUT_SLUG;
9
+ function getUserId(req) {
10
+ return req.user && req.user.id ? req.user.id : LOGGED_OUT_ID;
11
11
  }
12
12
 
13
13
  function buildCustomFormat(tokens, req, res) {
@@ -15,7 +15,7 @@ module.exports = ({ morgan, config, logger }) => {
15
15
  tokens.method(req, res),
16
16
  tokens.url(req, res),
17
17
  tokens.status(req, res),
18
- tokens[USER_SLUG](req),
18
+ tokens[USER_ID](req),
19
19
  tokens['response-time'](req, res),
20
20
  'ms',
21
21
  ].join(' ');
@@ -23,10 +23,10 @@ module.exports = ({ morgan, config, logger }) => {
23
23
 
24
24
  function buildMiddleware(labels) {
25
25
  // Setup Morgan with custom format and Apolitical Logger stream
26
- morgan.token(USER_SLUG, getUserSlug);
26
+ morgan.token(USER_ID, getUserId);
27
27
  const morganMiddleware = morgan(buildCustomFormat, logger.where(__filename, 'morganMiddleware', labels));
28
28
  return morganMiddleware;
29
29
  }
30
30
 
31
- return { getUserSlug, buildMiddleware };
31
+ return { getUserId, buildMiddleware };
32
32
  };
@@ -7,7 +7,7 @@ module.exports =
7
7
  JWT: { AUTH0 },
8
8
  },
9
9
  logger,
10
- loggerHelper: { getUserSlug },
10
+ loggerHelper: { getUserId },
11
11
  serverError: { GeneralError },
12
12
  }) =>
13
13
  ({ labels, redirectURL, fallbackController }) => {
@@ -35,12 +35,12 @@ module.exports =
35
35
  }
36
36
  }
37
37
  // Log the error with all the relevent info
38
- const userSlug = getUserSlug(req);
38
+ const userId = getUserId(req);
39
39
  if (req.log) {
40
- req.log.warn(message, { errors, userSlug });
40
+ req.log.warn(message, { errors, userId });
41
41
  } else {
42
42
  const errorLogger = logger.where(__filename, 'handler', labels);
43
- errorLogger.warn(message, { errors, userSlug });
43
+ errorLogger.warn(message, { errors, userId });
44
44
  }
45
45
  // Use the redirect URL to redirect the request
46
46
  if (redirectURL) {