@cardano-sdk/cardano-services-client
Advanced tools
Comparing version 0.20.2 to 0.20.3
import { HttpProviderConfigPaths, Provider } from '@cardano-sdk/core'; | ||
import { Logger } from 'ts-log'; | ||
import { AxiosAdapter, AxiosRequestConfig, AxiosResponseTransformer } from 'axios'; | ||
declare type ResponseTransformers<T> = { | ||
[K in keyof T]?: AxiosResponseTransformer; | ||
}; | ||
import { AxiosAdapter, AxiosRequestConfig } from 'axios'; | ||
export interface HttpProviderConfig<T extends Provider> { | ||
@@ -15,3 +12,2 @@ apiVersion: string; | ||
logger: Logger; | ||
responseTransformers?: ResponseTransformers<T>; | ||
serviceSlug: string; | ||
@@ -22,4 +18,3 @@ } | ||
}; | ||
export declare const createHttpProvider: <T extends Provider>({ apiVersion, baseUrl, axiosOptions, mapError, paths, adapter, logger, responseTransformers, serviceSlug }: HttpProviderConfig<T>) => T; | ||
export {}; | ||
export declare const createHttpProvider: <T extends Provider>({ apiVersion, baseUrl, axiosOptions, mapError, paths, adapter, logger, serviceSlug }: HttpProviderConfig<T>) => T; | ||
//# sourceMappingURL=HttpProvider.d.ts.map |
@@ -12,3 +12,15 @@ "use strict"; | ||
const isEmptyResponse = (response) => response === ''; | ||
const createHttpProvider = ({ apiVersion, baseUrl, axiosOptions, mapError, paths, adapter, logger, responseTransformers, serviceSlug }) => new Proxy({}, { | ||
const transformResponse = (v) => { | ||
if (!v) | ||
return v; | ||
if (typeof v === 'string') | ||
v = JSON.parse(v); | ||
return (0, util_1.fromSerializableObject)(v, { errorTypes: [core_1.ProviderError] }); | ||
}; | ||
const transformRequest = (data) => { | ||
if (!data) | ||
return data; | ||
return JSON.stringify((0, util_1.toSerializableObject)(data)); | ||
}; | ||
const createHttpProvider = ({ apiVersion, baseUrl, axiosOptions, mapError, paths, adapter, logger, serviceSlug }) => new Proxy({}, { | ||
get(_, prop) { | ||
@@ -19,3 +31,2 @@ if (prop === 'then') | ||
const urlPath = paths[method]; | ||
const transformResponse = responseTransformers && responseTransformers[method] ? responseTransformers[method] : (v) => v; | ||
if (!urlPath) | ||
@@ -32,2 +43,3 @@ throw new core_1.ProviderError(core_1.ProviderFailure.NotImplemented, `HttpProvider missing path for '${prop.toString()}'`); | ||
...axiosOptions?.headers, | ||
'Content-Type': 'application/json', | ||
'Version-Api': JSON.stringify(apiVersion), | ||
@@ -38,2 +50,4 @@ 'Version-Software': package_json_1.default.version | ||
responseType: 'json', | ||
transformRequest, | ||
transformResponse, | ||
url: urlPath | ||
@@ -44,11 +58,2 @@ }; | ||
const axiosInstance = axios_1.default.create(req); | ||
axiosInstance.interceptors.request.use((value) => { | ||
if (value.data) | ||
value.data = (0, util_1.toSerializableObject)(value.data); | ||
return value; | ||
}); | ||
axiosInstance.interceptors.response.use((value) => ({ | ||
...value, | ||
data: transformResponse((0, util_1.fromSerializableObject)(value.data, { errorTypes: [core_1.ProviderError] })) | ||
})); | ||
const response = (await axiosInstance.request(req)).data; | ||
@@ -60,3 +65,3 @@ return !isEmptyResponse(response) ? response : undefined; | ||
if (error.response) { | ||
const typedError = (0, util_1.fromSerializableObject)(error.response.data, { errorTypes: [core_1.ProviderError] }); | ||
const typedError = error.response.data; | ||
if (mapError) | ||
@@ -63,0 +68,0 @@ return mapError(typedError, method); |
import { HttpProviderConfigPaths, Provider } from '@cardano-sdk/core'; | ||
import { Logger } from 'ts-log'; | ||
import { AxiosAdapter, AxiosRequestConfig, AxiosResponseTransformer } from 'axios'; | ||
declare type ResponseTransformers<T> = { | ||
[K in keyof T]?: AxiosResponseTransformer; | ||
}; | ||
import { AxiosAdapter, AxiosRequestConfig } from 'axios'; | ||
export interface HttpProviderConfig<T extends Provider> { | ||
@@ -15,3 +12,2 @@ apiVersion: string; | ||
logger: Logger; | ||
responseTransformers?: ResponseTransformers<T>; | ||
serviceSlug: string; | ||
@@ -22,4 +18,3 @@ } | ||
}; | ||
export declare const createHttpProvider: <T extends Provider>({ apiVersion, baseUrl, axiosOptions, mapError, paths, adapter, logger, responseTransformers, serviceSlug }: HttpProviderConfig<T>) => T; | ||
export {}; | ||
export declare const createHttpProvider: <T extends Provider>({ apiVersion, baseUrl, axiosOptions, mapError, paths, adapter, logger, serviceSlug }: HttpProviderConfig<T>) => T; | ||
//# sourceMappingURL=HttpProvider.d.ts.map |
@@ -6,3 +6,15 @@ import { ProviderError, ProviderFailure } from '@cardano-sdk/core'; | ||
const isEmptyResponse = (response) => response === ''; | ||
export const createHttpProvider = ({ apiVersion, baseUrl, axiosOptions, mapError, paths, adapter, logger, responseTransformers, serviceSlug }) => new Proxy({}, { | ||
const transformResponse = (v) => { | ||
if (!v) | ||
return v; | ||
if (typeof v === 'string') | ||
v = JSON.parse(v); | ||
return fromSerializableObject(v, { errorTypes: [ProviderError] }); | ||
}; | ||
const transformRequest = (data) => { | ||
if (!data) | ||
return data; | ||
return JSON.stringify(toSerializableObject(data)); | ||
}; | ||
export const createHttpProvider = ({ apiVersion, baseUrl, axiosOptions, mapError, paths, adapter, logger, serviceSlug }) => new Proxy({}, { | ||
get(_, prop) { | ||
@@ -13,3 +25,2 @@ if (prop === 'then') | ||
const urlPath = paths[method]; | ||
const transformResponse = responseTransformers && responseTransformers[method] ? responseTransformers[method] : (v) => v; | ||
if (!urlPath) | ||
@@ -26,2 +37,3 @@ throw new ProviderError(ProviderFailure.NotImplemented, `HttpProvider missing path for '${prop.toString()}'`); | ||
...axiosOptions?.headers, | ||
'Content-Type': 'application/json', | ||
'Version-Api': JSON.stringify(apiVersion), | ||
@@ -32,2 +44,4 @@ 'Version-Software': packageJson.version | ||
responseType: 'json', | ||
transformRequest, | ||
transformResponse, | ||
url: urlPath | ||
@@ -38,11 +52,2 @@ }; | ||
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; | ||
@@ -54,3 +59,3 @@ return !isEmptyResponse(response) ? response : undefined; | ||
if (error.response) { | ||
const typedError = fromSerializableObject(error.response.data, { errorTypes: [ProviderError] }); | ||
const typedError = error.response.data; | ||
if (mapError) | ||
@@ -57,0 +62,0 @@ return mapError(typedError, method); |
{ | ||
"name": "@cardano-sdk/cardano-services-client", | ||
"version": "0.20.2", | ||
"version": "0.20.3", | ||
"description": "Cardano Services Client", | ||
@@ -41,5 +41,5 @@ "engines": { | ||
"devDependencies": { | ||
"@cardano-sdk/util-dev": "~0.22.4", | ||
"@cardano-sdk/util-dev": "~0.22.5", | ||
"@types/validator": "^13.7.1", | ||
"axios-mock-adapter": "^1.20.0", | ||
"axios-mock-adapter": "^2.0.0", | ||
"eslint": "^7.32.0", | ||
@@ -56,5 +56,5 @@ "express": "^4.17.3", | ||
"dependencies": { | ||
"@cardano-sdk/core": "~0.38.2", | ||
"@cardano-sdk/core": "~0.38.3", | ||
"@cardano-sdk/util": "~0.15.5", | ||
"axios": "^0.28.0", | ||
"axios": "^1.7.4", | ||
"class-validator": "^0.14.0", | ||
@@ -72,3 +72,3 @@ "isomorphic-ws": "^5.0.0", | ||
], | ||
"gitHead": "2554ac5404b55dd236381cf4c089d682148a12d7" | ||
"gitHead": "b7ec9fb6124405ac33d50b783d606911104a594d" | ||
} |
{ | ||
"name": "@cardano-sdk/cardano-services-client", | ||
"version": "0.20.2", | ||
"version": "0.20.3", | ||
"description": "Cardano Services Client", | ||
@@ -41,5 +41,5 @@ "engines": { | ||
"devDependencies": { | ||
"@cardano-sdk/util-dev": "~0.22.4", | ||
"@cardano-sdk/util-dev": "~0.22.5", | ||
"@types/validator": "^13.7.1", | ||
"axios-mock-adapter": "^1.20.0", | ||
"axios-mock-adapter": "^2.0.0", | ||
"eslint": "^7.32.0", | ||
@@ -56,5 +56,5 @@ "express": "^4.17.3", | ||
"dependencies": { | ||
"@cardano-sdk/core": "~0.38.2", | ||
"@cardano-sdk/core": "~0.38.3", | ||
"@cardano-sdk/util": "~0.15.5", | ||
"axios": "^0.28.0", | ||
"axios": "^1.7.4", | ||
"class-validator": "^0.14.0", | ||
@@ -72,3 +72,3 @@ "isomorphic-ws": "^5.0.0", | ||
], | ||
"gitHead": "2554ac5404b55dd236381cf4c089d682148a12d7" | ||
"gitHead": "b7ec9fb6124405ac33d50b783d606911104a594d" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7
476384
+ Addedaxios@1.7.9(transitive)
+ Addedis-typed-array@1.1.14(transitive)
+ Addedmath-intrinsics@1.0.0(transitive)
+ Addedwhich-typed-array@1.1.16(transitive)
- Removedaxios@0.28.1(transitive)
- Removedis-typed-array@1.1.15(transitive)
- Removedmath-intrinsics@1.1.0(transitive)
- Removedwhich-typed-array@1.1.18(transitive)
Updated@cardano-sdk/core@~0.38.3
Updatedaxios@^1.7.4