Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cardano-services-client): LW-10778 allow openapiVersion override when configuring client providers #1336

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading