diff --git a/server/services/OBPClientService.ts b/server/services/OBPClientService.ts index 872e17a..9952c52 100644 --- a/server/services/OBPClientService.ts +++ b/server/services/OBPClientService.ts @@ -26,6 +26,7 @@ */ import { Service } from 'typedi' +import { DEFAULT_OBP_API_VERSION } from '../../shared-constants' import { Version, API, @@ -69,7 +70,7 @@ export default class OBPClientService { } this.clientConfig = { baseUri: process.env.VITE_OBP_API_HOST, - version: process.env.VITE_OBP_API_VERSION as Version, + version: (process.env.VITE_OBP_API_VERSION ?? DEFAULT_OBP_API_VERSION) as Version, oauthConfig: this.oauthConfig } diff --git a/server/services/OBPConsentsService.ts b/server/services/OBPConsentsService.ts index 9fb3c72..46f841c 100644 --- a/server/services/OBPConsentsService.ts +++ b/server/services/OBPConsentsService.ts @@ -5,6 +5,7 @@ import OauthInjectedService from './OauthInjectedService' import { AxiosResponse } from 'axios' import axios from 'axios' import { Session } from 'express-session' +import { DEFAULT_OBP_API_VERSION } from '../../shared-constants' @Service() /** @@ -79,7 +80,7 @@ export default class OBPConsentsService { // I.e. give permission to Opey to do anything on behalf of the logged in user // Get the Consents API client from the OBP SDK - const client = await this.createUserConsentsClient(session, `/obp/${process.env.VITE_OBP_API_VERSION}/my/consents/IMPLICIT`, 'POST') + const client = await this.createUserConsentsClient(session, `/obp/${process.env.VITE_OBP_API_VERSION ?? DEFAULT_OBP_API_VERSION}/my/consents/IMPLICIT`, 'POST') if (!client) { throw new Error('Could not create Consents API client') } @@ -150,7 +151,7 @@ export default class OBPConsentsService { } try { - const response = await this._sendOBPRequest(`/obp/${process.env.VITE_OBP_API_VERSION}/user/current/consents/${consentId}`, 'GET', clientConfig) + const response = await this._sendOBPRequest(`/obp/${process.env.VITE_OBP_API_VERSION ?? DEFAULT_OBP_API_VERSION}/user/current/consents/${consentId}`, 'GET', clientConfig) session['opeyConfig'] = { authConfig: { @@ -182,7 +183,7 @@ export default class OBPConsentsService { // Get the Consents API client from the OBP SDK // The OBP SDK is messed up here, so we'll need to use Fetch until the SWAGGER WILL ACTUALLY WORK - // const client = await this.createUserConsentsClient(session, `/obp/${process.env.VITE_OBP_API_VERSION}/my/consents/IMPLICIT`, 'POST') + // const client = await this.createUserConsentsClient(session, `/obp/${process.env.VITE_OBP_API_VERSION ?? DEFAULT_OBP_API_VERSION}/my/consents/IMPLICIT`, 'POST') // if (!client) { // throw new Error('Could not create Consents API client') // } @@ -197,8 +198,8 @@ export default class OBPConsentsService { // We need to change this back to consent infos once OBP shows 'EXPIRED' in the status // Right now we have to check the JWT ourselves - const consentInfosPath = `/obp/${process.env.VITE_OBP_API_VERSION}/my/consents` - //const consentInfosPath = `/obp/${process.env.VITE_OBP_API_VERSION}/my/consent-infos` + const consentInfosPath = `/obp/${process.env.VITE_OBP_API_VERSION ?? DEFAULT_OBP_API_VERSION}/my/consents` + //const consentInfosPath = `/obp/${process.env.VITE_OBP_API_VERSION ?? DEFAULT_OBP_API_VERSION}/my/consent-infos` let opeyConsentId: string | null = null try { diff --git a/shared-constants.ts b/shared-constants.ts new file mode 100644 index 0000000..23405b7 --- /dev/null +++ b/shared-constants.ts @@ -0,0 +1,2 @@ +// DEFAULT_OBP_API_VERSION is used in case the environment variable VITE_OBP_API_VERSION is not set +export const DEFAULT_OBP_API_VERSION = 'v6.0.0' diff --git a/src/obp/index.ts b/src/obp/index.ts index dd2b9eb..2171167 100644 --- a/src/obp/index.ts +++ b/src/obp/index.ts @@ -26,8 +26,9 @@ */ import superagent from 'superagent' +import { DEFAULT_OBP_API_VERSION } from '../../shared-constants' -export const OBP_API_VERSION = import.meta.env.VITE_OBP_API_VERSION +export const OBP_API_VERSION = import.meta.env.VITE_OBP_API_VERSION ?? DEFAULT_OBP_API_VERSION export const OBP_API_DEFAULT_RESOURCE_DOC_VERSION = (import.meta.env.VITE_OBP_API_DEFAULT_RESOURCE_DOC_VERSION ?? `OBP${OBP_API_VERSION}`) const default_collection_name = 'Favourites'