@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.
@@ -22479,7 +22479,7 @@ const DocboxGateway = {
22479
22479
  },
22480
22480
  };
22481
22481
  function createDocboxRoutes(options) {
22482
- var _a, _b, _c, _d;
22482
+ var _a, _b, _c, _d, _e;
22483
22483
  let basePath = (_a = options.basePath) !== null && _a !== void 0 ? _a : DEFAULT_BASE_PATH;
22484
22484
  // Remove trailing slashes from base path
22485
22485
  if (basePath.endsWith('/'))
@@ -22494,6 +22494,7 @@ function createDocboxRoutes(options) {
22494
22494
  // Add interceptor to handle axios errors
22495
22495
  axiosInstance.interceptors.response.use((res) => res, createHandleAxiosError(options.docboxBaseURL));
22496
22496
  const getRequestUser = (_d = options.getRequestUser) !== null && _d !== void 0 ? _d : (() => null);
22497
+ const getApiKey = (_e = options.getApiKey) !== null && _e !== void 0 ? _e : (() => null);
22497
22498
  // Base route for creating document boxes
22498
22499
  const createBoxRoute = {
22499
22500
  path: `${basePath}/box`,
@@ -22515,7 +22516,8 @@ function createDocboxRoutes(options) {
22515
22516
  }
22516
22517
  const tenant = yield options.getRequestTenant(request);
22517
22518
  const user = yield getRequestUser(request);
22518
- return forwardRequest(axiosInstance, request, tenant, user, h, path);
22519
+ const apiKey = yield getApiKey();
22520
+ return forwardRequest(axiosInstance, request, tenant, user, apiKey, h, path);
22519
22521
  });
22520
22522
  },
22521
22523
  options: baseRouteOptions,
@@ -22537,7 +22539,8 @@ function createDocboxRoutes(options) {
22537
22539
  }
22538
22540
  const tenant = yield options.getRequestTenant(request);
22539
22541
  const user = yield getRequestUser(request);
22540
- return forwardRequest(axiosInstance, request, tenant, user, h, path);
22542
+ const apiKey = yield getApiKey();
22543
+ return forwardRequest(axiosInstance, request, tenant, user, apiKey, h, path);
22541
22544
  });
22542
22545
  },
22543
22546
  options: Object.assign(Object.assign({}, baseRouteOptions), baseForwardRouteOptions),
@@ -22562,7 +22565,8 @@ function createDocboxRoutes(options) {
22562
22565
  }
22563
22566
  const tenant = yield options.getRequestTenant(request);
22564
22567
  const user = yield getRequestUser(request);
22565
- return forwardRequest(axiosInstance, request, tenant, user, h, path);
22568
+ const apiKey = yield getApiKey();
22569
+ return forwardRequest(axiosInstance, request, tenant, user, apiKey, h, path);
22566
22570
  });
22567
22571
  },
22568
22572
  options: Object.assign(Object.assign(Object.assign({}, baseRouteOptions), baseForwardRouteOptions), { payload: Object.assign(Object.assign(Object.assign({}, baseRouteOptions.payload), baseForwardRouteOptions.payload), {
@@ -22604,13 +22608,17 @@ function isWriteRequest(request, path) {
22604
22608
  * @param axios Axios instance to forward the request through
22605
22609
  * @param request The request itself
22606
22610
  * @param user User performing the request
22611
+ * @param apiKey API key for requests
22607
22612
  * @param h Response toolkit for creating the response
22608
22613
  * @param path Path requested from the server
22609
22614
  */
22610
- function forwardRequest(axios, request, tenant, user, h, path) {
22615
+ function forwardRequest(axios, request, tenant, user, apiKey, h, path) {
22611
22616
  return __awaiter(this, void 0, void 0, function* () {
22612
22617
  const userHeaders = request.headers;
22613
22618
  const forwardHeaders = {};
22619
+ if (apiKey !== null) {
22620
+ forwardHeaders['x-docbox-api-key'] = apiKey;
22621
+ }
22614
22622
  // Forward content related headers
22615
22623
  if (userHeaders['accept'] !== undefined) {
22616
22624
  forwardHeaders['accept'] = userHeaders['accept'];