@defra/lis-hubs-infra-access 0.8.0 → 0.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/lis-hubs-infra-access",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Shared hub access and capability resolution for the livestock platform.",
5
5
  "main": "src/index.js",
6
6
  "repository": {
@@ -44,10 +44,12 @@
44
44
  },
45
45
  "peerDependencies": {
46
46
  "eslint": "^9.0.0",
47
+ "@hapi/boom": "10.0.1",
47
48
  "@hapi/wreck": "18.1.2"
48
49
  },
49
50
  "devDependencies": {
50
51
  "@defra/lis-infra-eslint-config": "^0.6.0",
52
+ "@hapi/boom": "10.0.1",
51
53
  "@hapi/wreck": "18.1.2",
52
54
  "@vitest/coverage-istanbul": "^4.1.10",
53
55
  "audit-ci": "^7.1.0",
@@ -1,10 +1,11 @@
1
1
  /** @import { Permission } from '../constants/permissions.js' */
2
- import { statusCodes } from '../constants/status-codes.js'
2
+ import Boom from '@hapi/boom'
3
3
  import { hasPermission } from './checks.js'
4
4
 
5
5
  /**
6
6
  * Creates a Hapi pre-handler that demands a specific permission.
7
- * Returns a 403 response if the permission is not granted.
7
+ * Returns a Boom 403 if the permission is not granted, so a host app's
8
+ * own onPreResponse error handling can render it consistently.
8
9
  * @param {object} [params={}] - Permission demand parameters.
9
10
  * @param {Permission} [params.permission] - The LIS permission to demand.
10
11
  * @param {Function} [params.getCph] - Optional function to extract CPH scope from the request.
@@ -23,9 +24,6 @@ export function demandPermission({ permission, getCph } = {}) {
23
24
  return h.continue
24
25
  }
25
26
 
26
- return h
27
- .response({ message: 'Permission denied' })
28
- .code(statusCodes.forbidden)
29
- .takeover()
27
+ return Boom.forbidden()
30
28
  }
31
29
  }
@@ -1,6 +1,6 @@
1
1
  /** @import { Module, ModuleAccess } from './module-access-resolution.js' */
2
+ import Boom from '@hapi/boom'
2
3
  import { isPublicRequest } from '../auth/tokens/index.js'
3
- import { statusCodes } from '../constants/status-codes.js'
4
4
  import { hasModuleAccess } from './access.js'
5
5
  import { normalizeModuleAccess } from './module-access-resolution.js'
6
6
 
@@ -34,10 +34,7 @@ export function createModuleAccessGuard({ assetPath, moduleAccess }) {
34
34
  return h.continue
35
35
  }
36
36
 
37
- return h
38
- .response({ message: 'Module access denied' })
39
- .code(statusCodes.forbidden)
40
- .takeover()
37
+ return Boom.forbidden()
41
38
  })
42
39
  }
43
40
  }