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(deps): bump axios from 0.28.1 to 1.7.4 in the npm_and_yarn group #1437

Merged
merged 3 commits into from
Aug 22, 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
4 changes: 2 additions & 2 deletions packages/cardano-services-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"devDependencies": {
"@cardano-sdk/util-dev": "workspace:~",
"@types/validator": "^13.7.1",
"axios-mock-adapter": "^1.20.0",
"axios-mock-adapter": "^2.0.0",
"eslint": "^7.32.0",
"express": "^4.17.3",
"get-port-please": "^2.5.0",
Expand All @@ -55,7 +55,7 @@
"dependencies": {
"@cardano-sdk/core": "workspace:~",
"@cardano-sdk/util": "workspace:~",
"axios": "^0.28.0",
"axios": "^1.7.4",
"class-validator": "^0.14.0",
"isomorphic-ws": "^5.0.0",
"json-bigint": "~1.0.0",
Expand Down
34 changes: 15 additions & 19 deletions packages/cardano-services-client/src/HttpProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
import { HttpProviderConfigPaths, Provider, ProviderError, ProviderFailure } from '@cardano-sdk/core';
import { Logger } from 'ts-log';
import { fromSerializableObject, toSerializableObject } from '@cardano-sdk/util';
import axios, { AxiosAdapter, AxiosRequestConfig, AxiosResponseTransformer } from 'axios';
import axios, { AxiosAdapter, AxiosRequestConfig, AxiosRequestTransformer, AxiosResponseTransformer } from 'axios';
import packageJson from '../package.json';

const isEmptyResponse = (response: any) => response === '';

type ResponseTransformers<T> = { [K in keyof T]?: AxiosResponseTransformer };

export interface HttpProviderConfig<T extends Provider> {
/** The OpenApi version, which forms part of the URL scheme */
apiVersion: string;
Expand All @@ -34,9 +32,6 @@ export interface HttpProviderConfig<T extends Provider> {
/** Logger strategy. */
logger: Logger;

/** Transform responses */
responseTransformers?: ResponseTransformers<T>;

/** Slug used in the URL path */
serviceSlug: string;
}
Expand All @@ -50,6 +45,16 @@ export type CreateHttpProviderConfig<T extends Provider> = Pick<
apiVersion?: string;
};

const transformResponse: AxiosResponseTransformer = (v) => {
if (!v) return v;
if (typeof v === 'string') v = JSON.parse(v);
return fromSerializableObject(v, { errorTypes: [ProviderError] });
};
const transformRequest: AxiosRequestTransformer = (data) => {
if (!data) return data;
return JSON.stringify(toSerializableObject(data));
};

/**
* Creates a HTTP client for specified provider type, following some conventions:
* - All methods use POST requests
Expand All @@ -68,7 +73,6 @@ export const createHttpProvider = <T extends Provider>({
paths,
adapter,
logger,
responseTransformers,
serviceSlug
}: HttpProviderConfig<T>): T =>
new Proxy<T>({} as T, {
Expand All @@ -77,8 +81,6 @@ export const createHttpProvider = <T extends Provider>({
if (prop === 'then') return;
const method = prop as keyof T;
const urlPath = paths[method];
const transformResponse =
responseTransformers && responseTransformers[method] ? responseTransformers[method]! : (v: unknown) => v;
if (!urlPath)
throw new ProviderError(ProviderFailure.NotImplemented, `HttpProvider missing path for '${prop.toString()}'`);
return async (...args: any[]) => {
Expand All @@ -90,32 +92,26 @@ export const createHttpProvider = <T extends Provider>({
data: { ...args[0] },
headers: {
...axiosOptions?.headers,
'Content-Type': 'application/json',
'Version-Api': JSON.stringify(apiVersion),
'Version-Software': packageJson.version
},
method: 'post',
responseType: 'json',
transformRequest,
transformResponse,
url: urlPath
};
logger.debug(`Sending ${req.method} request to ${req.baseURL}${req.url} with data:`);
logger.debug(req.data);

const axiosInstance = axios.create(req);

axiosInstance.interceptors.request.use((value) => {
if (value.data) value.data = toSerializableObject(value.data);
return value;
});
axiosInstance.interceptors.response.use((value) => ({
...value,
data: transformResponse(fromSerializableObject(value.data, { errorTypes: [ProviderError] }))
}));
const response = (await axiosInstance.request(req)).data;
return !isEmptyResponse(response) ? response : undefined;
} catch (error) {
if (axios.isAxiosError(error)) {
if (error.response) {
const typedError = fromSerializableObject(error.response.data, { errorTypes: [ProviderError] });
const typedError = error.response.data;
if (mapError) return mapError(typedError, method);
throw new ProviderError(ProviderFailure.Unknown, typedError);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/cardano-services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"@types/uuid": "^8.3.4",
"@types/wait-on": "^5.3.1",
"@types/ws": "^8.5.10",
"axios-mock-adapter": "^1.20.0",
"axios-mock-adapter": "^2.0.0",
"cbor": "^8.1.0",
"delay": "^5.0.0",
"dockerode": "^3.3.1",
Expand Down Expand Up @@ -101,7 +101,7 @@
"@cardano-sdk/util": "workspace:~",
"@cardano-sdk/util-rxjs": "workspace:~",
"@hapi/topo": "^6.0.2",
"axios": "^0.28.0",
"axios": "^1.7.4",
"backoff-rxjs": "^7.0.0",
"bignumber.js": "^9.1.0",
"body-parser": "^1.19.2",
Expand Down
6 changes: 3 additions & 3 deletions packages/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@
"@cardano-sdk/util-rxjs": "workspace:~",
"@cardano-sdk/wallet": "workspace:~",
"@dcspark/cardano-multiplatform-lib-nodejs": "^3.1.1",
"@vespaiach/axios-fetch-adapter": "^0.3.0",
"axios": "^0.28.0",
"@shiroyasha9/axios-fetch-adapter": "1.0.3",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll have to replace adapter package in Lace, the original one is unmaintained

"axios": "^1.7.4",
"bunyan": "^1.8.15",
"chalk": "4.1.2",
"cli-spinners": "^2.9.0",
Expand Down Expand Up @@ -150,7 +150,7 @@
"babel-loader": "^8.2.5",
"blake2b-no-wasm": "2.1.4",
"buffer": "^6.0.3",
"chromedriver": "^120.0.0",
"chromedriver": "^127.0.0",
"copy-webpack-plugin": "^10.2.4",
"crypto-browserify": "^3.12.0",
"delay": "^5.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/src/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import memoize from 'lodash/memoize.js';

const isNodeJs = typeof process !== 'undefined' && process.release?.name === 'node';
// tsc doesn't like the 'import' of this package, works with webpack
const customHttpFetchAdapter = isNodeJs ? undefined : require('@vespaiach/axios-fetch-adapter').default;
const customHttpFetchAdapter = isNodeJs ? undefined : require('@shiroyasha9/axios-fetch-adapter').default;

// CONSTANTS
const HTTP_PROVIDER = 'http';
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e/test/web-extension/extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"unlimitedStorage"
],
"content_security_policy": {
"extension_pages": "default-src 'self' http://localhost:3000; script-src 'self' 'wasm-unsafe-eval'; object-src 'self'; connect-src data: http://localhost:8080 https://backend.live-preprod.eks.lw.iog.io https://api.coingecko.com http://167.235.156.245:4000 http://localhost:3000 ws://localhost:3000 wss://localhost:3000 http://localhost:4011 ws://localhost:4011 wss://localhost:4011 http://localhost:4000 ws://localhost:4000 wss://localhost:4000 http://testnet-dev-backend.dev.lw.iog.io:80 http://localhost:4567 https://testnet-dev-backend.dev.lw.iog.io:443 https://preprod-api.v2.prod.lw.iog.io; style-src * 'unsafe-inline'; img-src * data:; font-src https://fonts.gstatic.com;"
"extension_pages": "default-src 'self' http://localhost:3000; script-src 'self' 'wasm-unsafe-eval'; object-src 'self'; connect-src data: http://localhost:8080 http://localhost:4014 ws://localhost:4100 https://backend.live-preprod.eks.lw.iog.io https://api.coingecko.com http://167.235.156.245:4000 http://localhost:3000 ws://localhost:3000 wss://localhost:3000 http://localhost:4011 ws://localhost:4011 wss://localhost:4011 http://localhost:4000 ws://localhost:4000 wss://localhost:4000 http://testnet-dev-backend.dev.lw.iog.io:80 http://localhost:4567 https://testnet-dev-backend.dev.lw.iog.io:443 https://preprod-api.v2.prod.lw.iog.io; style-src * 'unsafe-inline'; img-src * data:; font-src https://fonts.gstatic.com;"
},
"web_accessible_resources": [
{
Expand Down
1 change: 1 addition & 0 deletions packages/e2e/test/web-extension/webpack.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ module.exports = {
os: false,
path: false,
perf_hooks: false,
process: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also might have to do this in lace webpack config

stream: require.resolve('readable-stream'),
util: require.resolve('util/')
}
Expand Down
2 changes: 1 addition & 1 deletion packages/util-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"@cardano-sdk/key-management": "workspace:~",
"@cardano-sdk/util": "workspace:~",
"@types/dockerode": "^3.3.8",
"axios": "^0.28.0",
"axios": "^1.7.4",
"delay": "^5.0.0",
"dockerode": "^3.3.1",
"dockerode-utils": "^0.0.7",
Expand Down
Loading
Loading