Adding a shared constant for the default API Version which is used if

the env variable is not present.
This commit is contained in:
simonredfern 2025-11-07 07:07:17 +01:00
parent b5db95e9e3
commit eae18ad106
4 changed files with 12 additions and 7 deletions

View File

@ -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
}

View File

@ -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 {

2
shared-constants.ts Normal file
View File

@ -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'

View File

@ -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'