@defra/lis-hubs-infra-access 0.21.0 → 0.22.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.21.0",
3
+ "version": "0.22.0",
4
4
  "description": "Shared hub access and capability resolution for the livestock platform.",
5
5
  "main": "src/index.js",
6
6
  "repository": {
@@ -10,7 +10,6 @@
10
10
  "exports": {
11
11
  ".": "./src/module-access/index.js",
12
12
  "./auth": "./src/auth.js",
13
- "./ish-client": "./src/identity-service-helper-client.js",
14
13
  "./krds-client": "./src/krds-client.js"
15
14
  },
16
15
  "files": [
@@ -1,116 +0,0 @@
1
- import Wreck from '@hapi/wreck'
2
- import { requestContext } from '@defra/lis-hubs-infra-core'
3
- import { statusCodes } from './constants/status-codes.js'
4
-
5
- /**
6
- * @typedef {object} UserDetails
7
- * @property {string} id
8
- * @property {string} email
9
- * @property {string} firstName
10
- * @property {string} lastName
11
- * @property {string} displayName
12
- * @property {boolean} active
13
- */
14
-
15
- /**
16
- * @typedef {object} CphAssignment
17
- * @property {string} id
18
- * @property {string} countyParishHoldingId
19
- * @property {string} countyParishHoldingNumber
20
- * @property {string} userId
21
- * @property {string} roleId
22
- * @property {string} roleName
23
- * @property {string} email
24
- * @property {string} displayName
25
- */
26
-
27
- /**
28
- * @typedef {object} CphDelegation
29
- * @property {string} id
30
- * @property {string} countyParishHoldingId
31
- * @property {string} countyParishHoldingNumber
32
- * @property {string} delegatingUserId
33
- * @property {string} delegatingUserName
34
- * @property {string | null} delegatedUserId
35
- * @property {string | null} delegatedUserName
36
- * @property {string} delegatedUserRoleId
37
- * @property {string} delegatedUserRoleName
38
- * @property {string} delegatedUserEmail
39
- * @property {string | null} invitationExpiresAt
40
- * @property {string | null} invitationAcceptedAt
41
- * @property {string | null} invitationRejectedAt
42
- * @property {string | null} revokedAt
43
- * @property {string | null} revokedById
44
- * @property {string | null} revokedByName
45
- * @property {string | null} expiresAt
46
- * @property {boolean} active
47
- */
48
-
49
- /**
50
- * @typedef {object} UserProfile
51
- * @property {UserDetails} userDetails
52
- * @property {CphAssignment[]} directAssignments
53
- * @property {CphDelegation[]} inboundDelegations
54
- * @property {CphDelegation[]} outboundDelegations
55
- */
56
-
57
- export class IdentityServiceHelperClient {
58
- #baseUrl
59
- #apiKey
60
-
61
- /**
62
- * @param {string} baseUrl
63
- * @param {string} apiKey
64
- */
65
- constructor(baseUrl, apiKey) {
66
- this.#baseUrl = baseUrl
67
- this.#apiKey = apiKey
68
- }
69
-
70
- /**
71
- * Fetches a user's profile from identity-service-helper.
72
- *
73
- * @param {string} userId
74
- * @returns {Promise<UserProfile>}
75
- */
76
- async fetchUserProfile(userId) {
77
- let result
78
-
79
- try {
80
- result = await Wreck.get(`users/${userId}/profile`, {
81
- baseUrl: this.#baseUrl,
82
- json: true,
83
- headers: this.#getHeaders()
84
- })
85
- } catch (err) {
86
- throw this.#parseError(err.output?.statusCode, err.data?.payload)
87
- }
88
-
89
- if (result.res.statusCode >= statusCodes.badRequest) {
90
- throw this.#parseError(result.res.statusCode, result.payload)
91
- }
92
-
93
- return result.payload
94
- }
95
-
96
- #getHeaders() {
97
- return {
98
- 'x-api-key': this.#apiKey,
99
- 'x-correlation-id': requestContext.get('correlation_id'),
100
- 'x-cdp-request-id': requestContext.get('correlation_id')
101
- }
102
- }
103
-
104
- #parseError(statusCode, payload) {
105
- if (payload?.error?.code) {
106
- return new Error(`${payload.error.code} - ${payload.error.message}`)
107
- }
108
- if (payload?.detail || payload?.title) {
109
- return new Error(`${payload.status} - ${payload.detail || payload.title}`)
110
- }
111
- if (statusCode === statusCodes.unprocessableEntity) {
112
- return new Error('Validation failed')
113
- }
114
- return new Error(`Request failed - ${statusCode}`)
115
- }
116
- }