@apolitical/server 2.5.4-beta.1 → 2.5.6-rc.1

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/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [2.5.5] - 2022-07-19
9
+ ### Added
10
+ - Unit tests for `buildOptions` helper
11
+
8
12
  ## [2.5.4] - 2022-07-08
9
13
  ### Added
10
14
  - Generating apolitical-auth token function
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apolitical/server",
3
- "version": "2.5.4-beta.1",
3
+ "version": "2.5.6-rc.1",
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",
@@ -1,13 +1,14 @@
1
1
  'use strict';
2
2
 
3
3
  module.exports = ({ jwtEncodeHelper, config }) => {
4
- const { SESSION_SECRET } = config.SERVER;
4
+ const { SESSION_SECRET } = config;
5
5
  const {
6
6
  APOLITICAL: { ISSUER, ADMIN_ROLE, COOKIE_KEY },
7
7
  } = config.JWT;
8
8
 
9
- function generateAdminToken() {
10
- const token = jwtEncodeHelper(SESSION_SECRET, {
9
+ function generateAdminToken(sessionSecret) {
10
+ const secret = SESSION_SECRET || sessionSecret;
11
+ const token = jwtEncodeHelper(secret, {
11
12
  role: ADMIN_ROLE,
12
13
  admin: true,
13
14
  iss: ISSUER,
@@ -16,23 +17,23 @@ module.exports = ({ jwtEncodeHelper, config }) => {
16
17
  return token;
17
18
  }
18
19
 
19
- function buildHeaders({ authToken }) {
20
+ function buildHeaders({ authToken }, sessionSecret) {
20
21
  const headers = {};
21
- if (typeof authToken === 'boolean' && authToken) {
22
+ if (authToken && typeof authToken === 'boolean') {
22
23
  // When authToken is a boolean then generate an admin token
23
- const adminToken = generateAdminToken();
24
+ const adminToken = generateAdminToken(sessionSecret);
24
25
  Object.assign(headers, { Cookie: `${COOKIE_KEY}=${adminToken}` });
25
- } else if (typeof authToken === 'string' && authToken) {
26
+ } else if (authToken && typeof authToken === 'string') {
26
27
  // When authToken is a string then use the it as the token
27
28
  Object.assign(headers, { Cookie: `${COOKIE_KEY}=${authToken}` });
28
29
  }
29
30
  return headers;
30
31
  }
31
32
 
32
- function buildOptions({ headers, params, validateStatus, data }) {
33
+ function buildOptions({ headers, params, validateStatus, data, sessionSecret }) {
33
34
  const opts = {};
34
35
  if (headers) {
35
- Object.assign(opts, { headers: buildHeaders(headers) });
36
+ Object.assign(opts, { headers: buildHeaders(headers, sessionSecret) });
36
37
  }
37
38
  if (params) {
38
39
  Object.assign(opts, { params });