Skip to content

Commit eae18ad

Browse files
committed
Adding a shared constant for the default API Version which is used if
the env variable is not present.
1 parent b5db95e commit eae18ad

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

server/services/OBPClientService.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*/
2727

2828
import { Service } from 'typedi'
29+
import { DEFAULT_OBP_API_VERSION } from '../../shared-constants'
2930
import {
3031
Version,
3132
API,
@@ -69,7 +70,7 @@ export default class OBPClientService {
6970
}
7071
this.clientConfig = {
7172
baseUri: process.env.VITE_OBP_API_HOST,
72-
version: process.env.VITE_OBP_API_VERSION as Version,
73+
version: (process.env.VITE_OBP_API_VERSION ?? DEFAULT_OBP_API_VERSION) as Version,
7374
oauthConfig: this.oauthConfig
7475
}
7576

server/services/OBPConsentsService.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import OauthInjectedService from './OauthInjectedService'
55
import { AxiosResponse } from 'axios'
66
import axios from 'axios'
77
import { Session } from 'express-session'
8+
import { DEFAULT_OBP_API_VERSION } from '../../shared-constants'
89

910
@Service()
1011
/**
@@ -79,7 +80,7 @@ export default class OBPConsentsService {
7980
// I.e. give permission to Opey to do anything on behalf of the logged in user
8081

8182
// Get the Consents API client from the OBP SDK
82-
const client = await this.createUserConsentsClient(session, `/obp/${process.env.VITE_OBP_API_VERSION}/my/consents/IMPLICIT`, 'POST')
83+
const client = await this.createUserConsentsClient(session, `/obp/${process.env.VITE_OBP_API_VERSION ?? DEFAULT_OBP_API_VERSION}/my/consents/IMPLICIT`, 'POST')
8384
if (!client) {
8485
throw new Error('Could not create Consents API client')
8586
}
@@ -150,7 +151,7 @@ export default class OBPConsentsService {
150151
}
151152

152153
try {
153-
const response = await this._sendOBPRequest(`/obp/${process.env.VITE_OBP_API_VERSION}/user/current/consents/${consentId}`, 'GET', clientConfig)
154+
const response = await this._sendOBPRequest(`/obp/${process.env.VITE_OBP_API_VERSION ?? DEFAULT_OBP_API_VERSION}/user/current/consents/${consentId}`, 'GET', clientConfig)
154155

155156
session['opeyConfig'] = {
156157
authConfig: {
@@ -182,7 +183,7 @@ export default class OBPConsentsService {
182183

183184
// Get the Consents API client from the OBP SDK
184185
// The OBP SDK is messed up here, so we'll need to use Fetch until the SWAGGER WILL ACTUALLY WORK
185-
// const client = await this.createUserConsentsClient(session, `/obp/${process.env.VITE_OBP_API_VERSION}/my/consents/IMPLICIT`, 'POST')
186+
// const client = await this.createUserConsentsClient(session, `/obp/${process.env.VITE_OBP_API_VERSION ?? DEFAULT_OBP_API_VERSION}/my/consents/IMPLICIT`, 'POST')
186187
// if (!client) {
187188
// throw new Error('Could not create Consents API client')
188189
// }
@@ -197,8 +198,8 @@ export default class OBPConsentsService {
197198

198199
// We need to change this back to consent infos once OBP shows 'EXPIRED' in the status
199200
// Right now we have to check the JWT ourselves
200-
const consentInfosPath = `/obp/${process.env.VITE_OBP_API_VERSION}/my/consents`
201-
//const consentInfosPath = `/obp/${process.env.VITE_OBP_API_VERSION}/my/consent-infos`
201+
const consentInfosPath = `/obp/${process.env.VITE_OBP_API_VERSION ?? DEFAULT_OBP_API_VERSION}/my/consents`
202+
//const consentInfosPath = `/obp/${process.env.VITE_OBP_API_VERSION ?? DEFAULT_OBP_API_VERSION}/my/consent-infos`
202203

203204
let opeyConsentId: string | null = null
204205
try {

shared-constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// DEFAULT_OBP_API_VERSION is used in case the environment variable VITE_OBP_API_VERSION is not set
2+
export const DEFAULT_OBP_API_VERSION = 'v6.0.0'

src/obp/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
*/
2727

2828
import superagent from 'superagent'
29+
import { DEFAULT_OBP_API_VERSION } from '../../shared-constants'
2930

30-
export const OBP_API_VERSION = import.meta.env.VITE_OBP_API_VERSION
31+
export const OBP_API_VERSION = import.meta.env.VITE_OBP_API_VERSION ?? DEFAULT_OBP_API_VERSION
3132
export const OBP_API_DEFAULT_RESOURCE_DOC_VERSION =
3233
(import.meta.env.VITE_OBP_API_DEFAULT_RESOURCE_DOC_VERSION ?? `OBP${OBP_API_VERSION}`)
3334
const default_collection_name = 'Favourites'

0 commit comments

Comments
 (0)