diff --git a/packages/cardano-services-client/src/AssetInfoProvider/assetInfoHttpProvider.ts b/packages/cardano-services-client/src/AssetInfoProvider/assetInfoHttpProvider.ts index f6e2998be25..3b90a5316cc 100644 --- a/packages/cardano-services-client/src/AssetInfoProvider/assetInfoHttpProvider.ts +++ b/packages/cardano-services-client/src/AssetInfoProvider/assetInfoHttpProvider.ts @@ -17,7 +17,7 @@ const paths: HttpProviderConfigPaths = { export const assetInfoHttpProvider = (config: CreateHttpProviderConfig): AssetProvider => createHttpProvider({ ...config, - apiVersion: apiVersion.assetInfo, + apiVersion: config.apiVersion || apiVersion.assetInfo, paths, serviceSlug: 'asset' }); diff --git a/packages/cardano-services-client/src/ChainHistoryProvider/chainHistoryHttpProvider.ts b/packages/cardano-services-client/src/ChainHistoryProvider/chainHistoryHttpProvider.ts index e376b8730fa..3273908c252 100644 --- a/packages/cardano-services-client/src/ChainHistoryProvider/chainHistoryHttpProvider.ts +++ b/packages/cardano-services-client/src/ChainHistoryProvider/chainHistoryHttpProvider.ts @@ -21,7 +21,7 @@ export const chainHistoryHttpProvider = ( ): ChainHistoryProvider => createHttpProvider({ ...config, - apiVersion: apiVersion.chainHistory, + apiVersion: config.apiVersion || apiVersion.chainHistory, mapError: (error, method) => { if (method === 'healthCheck' && !error) { return { ok: false }; diff --git a/packages/cardano-services-client/src/HandleProvider/handleHttpProvider.ts b/packages/cardano-services-client/src/HandleProvider/handleHttpProvider.ts index 90f6459f0a0..fa125d7e27c 100644 --- a/packages/cardano-services-client/src/HandleProvider/handleHttpProvider.ts +++ b/packages/cardano-services-client/src/HandleProvider/handleHttpProvider.ts @@ -10,7 +10,7 @@ import { apiVersion } from '../version'; export const handleHttpProvider = (config: CreateHttpProviderConfig): HandleProvider => createHttpProvider({ ...config, - apiVersion: apiVersion.handle, + apiVersion: config.apiVersion || apiVersion.handle, paths: handleProviderPaths, serviceSlug: 'handle' }); diff --git a/packages/cardano-services-client/src/HttpProvider.ts b/packages/cardano-services-client/src/HttpProvider.ts index 75831733da5..85c1b7fea08 100644 --- a/packages/cardano-services-client/src/HttpProvider.ts +++ b/packages/cardano-services-client/src/HttpProvider.ts @@ -45,7 +45,10 @@ export interface HttpProviderConfig { export type CreateHttpProviderConfig = Pick< HttpProviderConfig, 'baseUrl' | 'adapter' | 'logger' ->; +> & { + /** Override the OpenApi version */ + apiVersion?: string; +}; /** * Creates a HTTP client for specified provider type, following some conventions: diff --git a/packages/cardano-services-client/src/NetworkInfoProvider/networkInfoHttpProvider.ts b/packages/cardano-services-client/src/NetworkInfoProvider/networkInfoHttpProvider.ts index c2241eaffcc..1f07b70f740 100644 --- a/packages/cardano-services-client/src/NetworkInfoProvider/networkInfoHttpProvider.ts +++ b/packages/cardano-services-client/src/NetworkInfoProvider/networkInfoHttpProvider.ts @@ -21,7 +21,7 @@ const paths: HttpProviderConfigPaths = { export const networkInfoHttpProvider = (config: CreateHttpProviderConfig): NetworkInfoProvider => createHttpProvider({ ...config, - apiVersion: apiVersion.networkInfo, + apiVersion: config.apiVersion || apiVersion.networkInfo, paths, serviceSlug: 'network-info' }); diff --git a/packages/cardano-services-client/src/RewardsProvider/rewardsHttpProvider.ts b/packages/cardano-services-client/src/RewardsProvider/rewardsHttpProvider.ts index 5b58e0408dc..86741d4e1d6 100644 --- a/packages/cardano-services-client/src/RewardsProvider/rewardsHttpProvider.ts +++ b/packages/cardano-services-client/src/RewardsProvider/rewardsHttpProvider.ts @@ -18,7 +18,7 @@ const paths: HttpProviderConfigPaths = { export const rewardsHttpProvider = (config: CreateHttpProviderConfig): RewardsProvider => createHttpProvider({ ...config, - apiVersion: apiVersion.rewards, + apiVersion: config.apiVersion || apiVersion.rewards, // eslint-disable-next-line @typescript-eslint/no-explicit-any mapError: (error: any, method) => { if (method === 'healthCheck') { diff --git a/packages/cardano-services-client/src/StakePoolProvider/stakePoolHttpProvider.ts b/packages/cardano-services-client/src/StakePoolProvider/stakePoolHttpProvider.ts index 41d167bef14..1f7ff33a32b 100644 --- a/packages/cardano-services-client/src/StakePoolProvider/stakePoolHttpProvider.ts +++ b/packages/cardano-services-client/src/StakePoolProvider/stakePoolHttpProvider.ts @@ -17,7 +17,7 @@ const paths: HttpProviderConfigPaths = { export const stakePoolHttpProvider = (config: CreateHttpProviderConfig): StakePoolProvider => createHttpProvider({ ...config, - apiVersion: apiVersion.stakePool, + apiVersion: config.apiVersion || apiVersion.stakePool, paths, serviceSlug: 'stake-pool' }); diff --git a/packages/cardano-services-client/src/TxSubmitProvider/txSubmitHttpProvider.ts b/packages/cardano-services-client/src/TxSubmitProvider/txSubmitHttpProvider.ts index 16dbc5581ca..cb2d85ba798 100644 --- a/packages/cardano-services-client/src/TxSubmitProvider/txSubmitHttpProvider.ts +++ b/packages/cardano-services-client/src/TxSubmitProvider/txSubmitHttpProvider.ts @@ -70,7 +70,7 @@ const codeToProviderFailure = (code: GeneralCardanoNodeErrorCode | TxSubmissionE export const txSubmitHttpProvider = (config: CreateHttpProviderConfig): TxSubmitProvider => createHttpProvider({ ...config, - apiVersion: apiVersion.txSubmit, + apiVersion: config.apiVersion || apiVersion.txSubmit, mapError: (error: any, method) => { switch (method) { case 'healthCheck': { diff --git a/packages/cardano-services-client/src/UtxoProvider/utxoHttpProvider.ts b/packages/cardano-services-client/src/UtxoProvider/utxoHttpProvider.ts index f28a15078d0..b756090b7d0 100644 --- a/packages/cardano-services-client/src/UtxoProvider/utxoHttpProvider.ts +++ b/packages/cardano-services-client/src/UtxoProvider/utxoHttpProvider.ts @@ -17,7 +17,7 @@ const paths: HttpProviderConfigPaths = { export const utxoHttpProvider = (config: CreateHttpProviderConfig): UtxoProvider => createHttpProvider({ ...config, - apiVersion: apiVersion.utxo, + apiVersion: config.apiVersion || apiVersion.utxo, // eslint-disable-next-line @typescript-eslint/no-explicit-any mapError: (error: any, method) => { if (method === 'healthCheck') { diff --git a/packages/cardano-services-client/test/ChainHistoryProvider/chainHistoryProvider.test.ts b/packages/cardano-services-client/test/ChainHistoryProvider/chainHistoryProvider.test.ts index 213ea735c91..ee9ace08eca 100644 --- a/packages/cardano-services-client/test/ChainHistoryProvider/chainHistoryProvider.test.ts +++ b/packages/cardano-services-client/test/ChainHistoryProvider/chainHistoryProvider.test.ts @@ -37,6 +37,17 @@ describe('chainHistoryProvider', () => { const provider = chainHistoryHttpProvider(config); await expect(provider.healthCheck()).resolves.toEqual({ ok: false }); }); + + it('uses custom apiVersion', async () => { + axiosMock.onPost().replyOnce(200, { ok: true }); + const provider = chainHistoryHttpProvider({ ...config, adapter: axiosMock.adapter(), apiVersion: '100' }); + await provider.healthCheck(); + expect(axiosMock.history).toEqual( + expect.objectContaining({ + post: [expect.objectContaining({ baseURL: `${config.baseUrl}/v100/chain-history` })] + }) + ); + }); }); describe('blocks', () => {