@docbox-nz/hapi-gateway 0.1.0 → 0.2.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/README.md CHANGED
@@ -68,7 +68,7 @@ server.register({
68
68
  });
69
69
  ```
70
70
 
71
- ## Complex Routing Setup
71
+ ## Custom Routing Setup
72
72
 
73
73
  If you have a more complex routing setup for your hapi app, you can use the `createDocboxRoutes` function to create a docbox setup and obtain a list of routes that you can manually add using `server.route`
74
74
 
@@ -22481,7 +22481,7 @@ const DocboxGateway = {
22481
22481
  },
22482
22482
  };
22483
22483
  function createDocboxRoutes(options) {
22484
- var _a, _b, _c, _d;
22484
+ var _a, _b, _c, _d, _e;
22485
22485
  let basePath = (_a = options.basePath) !== null && _a !== void 0 ? _a : DEFAULT_BASE_PATH;
22486
22486
  // Remove trailing slashes from base path
22487
22487
  if (basePath.endsWith('/'))
@@ -22496,6 +22496,7 @@ function createDocboxRoutes(options) {
22496
22496
  // Add interceptor to handle axios errors
22497
22497
  axiosInstance.interceptors.response.use((res) => res, createHandleAxiosError(options.docboxBaseURL));
22498
22498
  const getRequestUser = (_d = options.getRequestUser) !== null && _d !== void 0 ? _d : (() => null);
22499
+ const getApiKey = (_e = options.getApiKey) !== null && _e !== void 0 ? _e : (() => null);
22499
22500
  // Base route for creating document boxes
22500
22501
  const createBoxRoute = {
22501
22502
  path: `${basePath}/box`,
@@ -22517,7 +22518,8 @@ function createDocboxRoutes(options) {
22517
22518
  }
22518
22519
  const tenant = yield options.getRequestTenant(request);
22519
22520
  const user = yield getRequestUser(request);
22520
- return forwardRequest(axiosInstance, request, tenant, user, h, path);
22521
+ const apiKey = yield getApiKey();
22522
+ return forwardRequest(axiosInstance, request, tenant, user, apiKey, h, path);
22521
22523
  });
22522
22524
  },
22523
22525
  options: baseRouteOptions,
@@ -22539,7 +22541,8 @@ function createDocboxRoutes(options) {
22539
22541
  }
22540
22542
  const tenant = yield options.getRequestTenant(request);
22541
22543
  const user = yield getRequestUser(request);
22542
- return forwardRequest(axiosInstance, request, tenant, user, h, path);
22544
+ const apiKey = yield getApiKey();
22545
+ return forwardRequest(axiosInstance, request, tenant, user, apiKey, h, path);
22543
22546
  });
22544
22547
  },
22545
22548
  options: Object.assign(Object.assign({}, baseRouteOptions), baseForwardRouteOptions),
@@ -22564,7 +22567,8 @@ function createDocboxRoutes(options) {
22564
22567
  }
22565
22568
  const tenant = yield options.getRequestTenant(request);
22566
22569
  const user = yield getRequestUser(request);
22567
- return forwardRequest(axiosInstance, request, tenant, user, h, path);
22570
+ const apiKey = yield getApiKey();
22571
+ return forwardRequest(axiosInstance, request, tenant, user, apiKey, h, path);
22568
22572
  });
22569
22573
  },
22570
22574
  options: Object.assign(Object.assign(Object.assign({}, baseRouteOptions), baseForwardRouteOptions), { payload: Object.assign(Object.assign(Object.assign({}, baseRouteOptions.payload), baseForwardRouteOptions.payload), {
@@ -22606,13 +22610,17 @@ function isWriteRequest(request, path) {
22606
22610
  * @param axios Axios instance to forward the request through
22607
22611
  * @param request The request itself
22608
22612
  * @param user User performing the request
22613
+ * @param apiKey API key for requests
22609
22614
  * @param h Response toolkit for creating the response
22610
22615
  * @param path Path requested from the server
22611
22616
  */
22612
- function forwardRequest(axios, request, tenant, user, h, path) {
22617
+ function forwardRequest(axios, request, tenant, user, apiKey, h, path) {
22613
22618
  return __awaiter(this, void 0, void 0, function* () {
22614
22619
  const userHeaders = request.headers;
22615
22620
  const forwardHeaders = {};
22621
+ if (apiKey !== null) {
22622
+ forwardHeaders['x-docbox-api-key'] = apiKey;
22623
+ }
22616
22624
  // Forward content related headers
22617
22625
  if (userHeaders['accept'] !== undefined) {
22618
22626
  forwardHeaders['accept'] = userHeaders['accept'];