Skip to content

Commit

Permalink
Merge pull request #1336 from input-output-hk/chore/tmp-lower-chain-h…
Browse files Browse the repository at this point in the history
…istory-version

chore(cardano-services-client): LW-10778 allow openapiVersion override when configuring client providers
  • Loading branch information
mirceahasegan authored Jun 18, 2024
2 parents 53b8e86 + 89f5ff4 commit c16489d
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const paths: HttpProviderConfigPaths<AssetProvider> = {
export const assetInfoHttpProvider = (config: CreateHttpProviderConfig<AssetProvider>): AssetProvider =>
createHttpProvider<AssetProvider>({
...config,
apiVersion: apiVersion.assetInfo,
apiVersion: config.apiVersion || apiVersion.assetInfo,
paths,
serviceSlug: 'asset'
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const chainHistoryHttpProvider = (
): ChainHistoryProvider =>
createHttpProvider<ChainHistoryProvider>({
...config,
apiVersion: apiVersion.chainHistory,
apiVersion: config.apiVersion || apiVersion.chainHistory,
mapError: (error, method) => {
if (method === 'healthCheck' && !error) {
return { ok: false };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { apiVersion } from '../version';
export const handleHttpProvider = (config: CreateHttpProviderConfig<HandleProvider>): HandleProvider =>
createHttpProvider<HandleProvider>({
...config,
apiVersion: apiVersion.handle,
apiVersion: config.apiVersion || apiVersion.handle,
paths: handleProviderPaths,
serviceSlug: 'handle'
});
5 changes: 4 additions & 1 deletion packages/cardano-services-client/src/HttpProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export interface HttpProviderConfig<T extends Provider> {
export type CreateHttpProviderConfig<T extends Provider> = Pick<
HttpProviderConfig<T>,
'baseUrl' | 'adapter' | 'logger'
>;
> & {
/** Override the OpenApi version */
apiVersion?: string;
};

/**
* Creates a HTTP client for specified provider type, following some conventions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const paths: HttpProviderConfigPaths<NetworkInfoProvider> = {
export const networkInfoHttpProvider = (config: CreateHttpProviderConfig<NetworkInfoProvider>): NetworkInfoProvider =>
createHttpProvider<NetworkInfoProvider>({
...config,
apiVersion: apiVersion.networkInfo,
apiVersion: config.apiVersion || apiVersion.networkInfo,
paths,
serviceSlug: 'network-info'
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const paths: HttpProviderConfigPaths<RewardsProvider> = {
export const rewardsHttpProvider = (config: CreateHttpProviderConfig<RewardsProvider>): RewardsProvider =>
createHttpProvider<RewardsProvider>({
...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') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const paths: HttpProviderConfigPaths<StakePoolProvider> = {
export const stakePoolHttpProvider = (config: CreateHttpProviderConfig<StakePoolProvider>): StakePoolProvider =>
createHttpProvider<StakePoolProvider>({
...config,
apiVersion: apiVersion.stakePool,
apiVersion: config.apiVersion || apiVersion.stakePool,
paths,
serviceSlug: 'stake-pool'
});
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const codeToProviderFailure = (code: GeneralCardanoNodeErrorCode | TxSubmissionE
export const txSubmitHttpProvider = (config: CreateHttpProviderConfig<TxSubmitProvider>): TxSubmitProvider =>
createHttpProvider<TxSubmitProvider>({
...config,
apiVersion: apiVersion.txSubmit,
apiVersion: config.apiVersion || apiVersion.txSubmit,
mapError: (error: any, method) => {
switch (method) {
case 'healthCheck': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const paths: HttpProviderConfigPaths<UtxoProvider> = {
export const utxoHttpProvider = (config: CreateHttpProviderConfig<UtxoProvider>): UtxoProvider =>
createHttpProvider<UtxoProvider>({
...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') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit c16489d

Please sign in to comment.