@apolitical/server 2.7.0-rc.2 → 2.7.0-rc.3

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
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
  ## [2.7.0] - 2022-08-22
9
9
  ### Added
10
10
  - Strict routing parameter to allow treating "/foo" and "/foo/" as different
11
+ - New `buildQueryString` function to the `request` helper
11
12
 
12
13
  ## [2.6.0] - 2022-07-25
13
14
  ### Updated
package/README.md CHANGED
@@ -27,10 +27,10 @@ This section covers how to use most of the functionally exposed by the __Apoliti
27
27
  First of all, include the __Apolitical Server__:
28
28
 
29
29
  ```js
30
- const { start, stop, jwt, errors, middlewares } = require('@apolitical/server');
30
+ const { start, stop, jwt, errors, middlewares, request } = require('@apolitical/server');
31
31
  ```
32
32
 
33
- Bear in mind, the `start`, `stop`, `jwt`, `errors` and `middlewares` variables will be used and explained in the examples listed below.
33
+ Bear in mind, the `start`, `stop`, `jwt`, `errors`, `middlewares`, `request` variables will be used and explained in the examples listed below.
34
34
 
35
35
  ### Quickstart
36
36
 
@@ -249,14 +249,15 @@ The `swaggerDocument` variable can be provided when starting the server to defin
249
249
 
250
250
  For usage examples, see [jwt.apolitical.spec.js](tests/../test/integration/jwt.apolitical.spec.js) test cases.
251
251
 
252
- ### Options helper
252
+ ### Request Helper
253
253
 
254
- The __Apolitical Server__ comes with an optsHelper function that can be used to generate an apolitical_auth header cookie when needed. This functionality is especially useful to generate an admin token when making request from one api to another.
254
+ The __Apolitical Server__ comes with a request helper functions.
255
255
 
256
- ```js
256
+ One of those functions is `buildOptions` that can be used to generate an `apolitical_auth` header cookie when needed. This functionality is especially useful to generate an admin token when making request from one api to another.
257
257
 
258
+ ```js
258
259
  // Instantiate the hellper with a session secret
259
- const { buildOptions } = optsHelper({ sessionSecret: 'hello' });
260
+ const { buildOptions } = request({ sessionSecret: 'hello' });
260
261
 
261
262
  // If generating an admin token: authToken must be truthy boolean
262
263
  buildOptions({ headers: { authToken: true }})
@@ -265,3 +266,11 @@ buildOptions({ headers: { authToken: true }})
265
266
  buildOptions({ headers: { authToken: 'some-token' }})
266
267
  ```
267
268
 
269
+ Also, you can use `buildQueryString` to stringify a query variable from a valid Express `req.query` object:
270
+
271
+ ```js
272
+ const { buildQueryString } = request({});
273
+
274
+ // Build query string from request query object
275
+ const queryString = buildQueryString(req.query);
276
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apolitical/server",
3
- "version": "2.7.0-rc.2",
3
+ "version": "2.7.0-rc.3",
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",
@@ -44,6 +44,7 @@
44
44
  "passport": "0.6.0",
45
45
  "passport-jwt": "4.0.0",
46
46
  "prerender-node": "3.5.0",
47
+ "qs": "6.11.0",
47
48
  "swagger-ui-express": "4.4.0"
48
49
  },
49
50
  "devDependencies": {
package/src/container.js CHANGED
@@ -19,6 +19,7 @@ const morgan = require('morgan');
19
19
  const passport = require('passport');
20
20
  const passportJwt = require('passport-jwt');
21
21
  const prerender = require('prerender-node');
22
+ const qs = require('qs');
22
23
  const swaggerUi = require('swagger-ui-express');
23
24
  // Internal Modules
24
25
  const apoliticalLogger = require('@apolitical/logger');
@@ -33,7 +34,7 @@ const jwtDecodeHelper = require('./helpers/jwt/decode.helper');
33
34
  const jwtEncodeHelper = require('./helpers/jwt/encode.helper');
34
35
  const jwtPassportHelper = require('./helpers/jwt/passport.helper');
35
36
  const loggerHelper = require('./helpers/logger.helper');
36
- const optsHelper = require('./helpers/opts.helper');
37
+ const requestHelper = require('./helpers/request.helper');
37
38
  // Loaders
38
39
  const documentationLoader = require('./loaders/documentation.loader');
39
40
  const expressLoader = require('./loaders/express.loader');
@@ -74,6 +75,7 @@ container.register({
74
75
  passport: asValue(passport),
75
76
  passportJwt: asValue(passportJwt),
76
77
  prerender: asValue(prerender),
78
+ qs: asValue(qs),
77
79
  swaggerUi: asValue(swaggerUi),
78
80
  // Internal Modules
79
81
  apoliticalLogger: asValue(apoliticalLogger),
@@ -88,7 +90,7 @@ container.register({
88
90
  jwtEncodeHelper: asFunction(jwtEncodeHelper).singleton(),
89
91
  jwtPassportHelper: asFunction(jwtPassportHelper).singleton(),
90
92
  loggerHelper: asFunction(loggerHelper).singleton(),
91
- optsHelper: asFunction(optsHelper).singleton(),
93
+ requestHelper: asFunction(requestHelper).singleton(),
92
94
  // Loaders
93
95
  documentationLoader: asFunction(documentationLoader).singleton(),
94
96
  expressLoader: asFunction(expressLoader).singleton(),
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  module.exports =
4
- ({ jwtEncodeHelper, config }) =>
4
+ ({ qs, jwtEncodeHelper, config }) =>
5
5
  ({ sessionSecret }) => {
6
6
  const {
7
7
  APOLITICAL: { ISSUER, ADMIN_ROLE, COOKIE_KEY },
@@ -47,5 +47,10 @@ module.exports =
47
47
  return opts;
48
48
  }
49
49
 
50
- return { buildOptions };
50
+ function buildQueryString({ query = {} } = {}) {
51
+ const queryString = qs.stringify(query);
52
+ return queryString ? `?${queryString}` : '';
53
+ }
54
+
55
+ return { buildOptions, buildQueryString };
51
56
  };
@@ -7,7 +7,7 @@ module.exports = ({
7
7
  healthService: { registerShutdown },
8
8
  jwtService,
9
9
  serverError,
10
- optsHelper,
10
+ requestHelper,
11
11
  }) => {
12
12
  // Register shutdown to clean up any resources used by the express app
13
13
  registerShutdown(shutdown);
@@ -21,6 +21,6 @@ module.exports = ({
21
21
  authentication: authenticationMiddleware,
22
22
  authorisation: authorisationMiddleware,
23
23
  },
24
- request: optsHelper,
24
+ request: requestHelper,
25
25
  };
26
26
  };