Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lifeomic/axios-fetch

Package Overview
Dependencies
Maintainers
3
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lifeomic/axios-fetch - npm Package Compare versions

Comparing version 2.0.3-pr-88-1317337924-1633629756.0 to 2.0.3-pr-90-1337554421-1634130165.0

.eslintrc

20

package.json
{
"name": "@lifeomic/axios-fetch",
"version": "2.0.3-pr-88-1317337924-1633629756.0",
"version": "2.0.3-pr-90-1337554421-1634130165.0",
"description": "A WebAPI Fetch implementation backed by an Axios client",

@@ -14,2 +14,6 @@ "main": "src/index.js",

},
"repository": {
"type": "git",
"url": "https://github.com/lifeomic/axios-fetch.git"
},
"engines": {

@@ -33,15 +37,15 @@ "node": ">=12"

"devDependencies": {
"@lifeomic/eslint-config-standards": "^1.2.1",
"@types/lodash": "^4.14.175",
"@lifeomic/eslint-plugin-node": "^2.0.1",
"@types/sinon": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"ava": "^3.15.0",
"axios": "0.22.0",
"axios": "^0.21.4",
"coveralls": "^3.1.0",
"eslint": "^7.32.0",
"lodash": "^4.17.21",
"eslint": "^6.0.0",
"nock": "^11.3.3",
"nyc": "^15.0.0",
"sinon": "^10.0.1",
"ts-node": "^10.2.1",
"typescript": "^4.4.3"
"ts-node": "^9.1.1",
"typescript": "^4.2.4"
},

@@ -48,0 +52,0 @@ "dependencies": {

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildAxiosFetch = void 0;
const node_fetch_1 = require("node-fetch");
const typeUtils_1 = require("./typeUtils");
const form_data_1 = __importDefault(require("form-data"));
/**
* A Fetch WebAPI implementation based on the Axios client
*/
const axiosFetch = (axios, transformer = (config) => config) => async (input, init = {}) => {
const rawHeaders = (0, typeUtils_1.createAxiosHeaders)(init.headers);
const lowerCasedHeaders = Object.keys(rawHeaders)
async function axiosFetch(axios,
// Convert the `fetch` style arguments into a Axios style config
transformer, input, init = {}) {
const rawHeaders = init.headers || {};
const lowerCasedHeaders = Object.keys(rawHeaders).filter(key => rawHeaders[key])
.reduce((acc, key) => {

@@ -20,5 +25,5 @@ acc[key.toLowerCase()] = rawHeaders[key];

const rawConfig = {
url: (0, typeUtils_1.getUrl)(input),
url: input,
method: init.method || 'GET',
data: init.body,
data: typeof init.body === 'undefined' || init.body instanceof form_data_1.default ? init.body : String(init.body),
headers: lowerCasedHeaders,

@@ -29,5 +34,5 @@ // Force the response to an arraybuffer type. Without this, the Response

// NOTE: Don't use 'stream' because it's not supported in the browser
responseType: 'arraybuffer',
responseType: 'arraybuffer'
};
const config = transformer(rawConfig, input, init);
const config = transformer ? transformer(rawConfig, input, init) : rawConfig;
let result;

@@ -45,12 +50,13 @@ try {

}
const fetchHeaders = new node_fetch_1.Headers(result.headers);
return new node_fetch_1.Response(result.data, {
status: result.status,
statusText: result.statusText,
headers: (0, typeUtils_1.createFetchHeaders)(result.headers),
headers: fetchHeaders
});
};
}
function buildAxiosFetch(axios, transformer) {
return axiosFetch(axios, transformer);
return axiosFetch.bind(undefined, axios, transformer);
}
exports.buildAxiosFetch = buildAxiosFetch;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJpbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSwyQ0FBZ0U7QUFFaEUsMkNBQTZFO0FBZ0I3RTs7R0FFRztBQUNILE1BQU0sVUFBVSxHQUF5RSxDQUN2RixLQUFLLEVBQ0wsV0FBVyxHQUFHLENBQUMsTUFBTSxFQUFFLEVBQUUsQ0FBQyxNQUFNLEVBQ2hDLEVBQUUsQ0FBQyxLQUFL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dCwgaW5pdCkgOiByYXdDb25maWc7XG5cbiAgbGV0IHJlc3VsdDtcbiAgdHJ5IHtcbiAgICByZXN1bHQgPSBhd2FpdCBheGlvcy5yZXF1ZXN0KGNvbmZpZyk7XG4gIH0gY2F0Y2ggKGVycjogYW55KSB7XG4gICAgaWYgKGVyci5yZXNwb25zZSkge1xuICAgICAgcmVzdWx0ID0gZXJyLnJlc3BvbnNlO1xuICAgIH0gZWxzZSB7XG4gICAgICB0aHJvdyBlcnI7XG4gICAgfVxuICB9XG5cbiAgY29uc3QgZmV0Y2hIZWFkZXJzID0gbmV3IEZldGNoSGVhZGVycyhyZXN1bHQuaGVhZGVycyk7XG5cbiAgcmV0dXJuIG5ldyBSZXNwb25zZShyZXN1bHQuZGF0YSwge1xuICAgIHN0YXR1czogcmVzdWx0LnN0YXR1cyxcbiAgICBzdGF0dXNUZXh0OiByZXN1bHQuc3RhdHVzVGV4dCxcbiAgICBoZWFkZXJzOiBmZXRjaEhlYWRlcnNcbiAgfSk7XG59XG5cbmV4cG9ydCBmdW5jdGlvbiBidWlsZEF4aW9zRmV0Y2ggKGF4aW9zOiBBeGlvc0luc3RhbmNlLCB0cmFuc2Zvcm1lcj86IEF4aW9zVHJhbnNmb3JtZXIpOiBBeGlvc0ZldGNoIHtcbiAgcmV0dXJuIGF4aW9zRmV0Y2guYmluZCh1bmRlZmluZWQsIGF4aW9zLCB0cmFuc2Zvcm1lcik7XG59XG4iXX0=

57

src/index.ts

@@ -1,18 +0,15 @@

import { Response, RequestInit, RequestInfo } from 'node-fetch';
import { Response, Headers as FetchHeaders } from 'node-fetch';
import FormData from 'form-data';
import { AxiosInstance, AxiosRequestConfig } from './types';
import { createFetchHeaders, createAxiosHeaders, getUrl } from './typeUtils';
export interface FetchInit extends Omit<RequestInit, 'body'> {
method?: string | AxiosRequestConfig['method'];
body?: RequestInit['body'] | Record<string, any>;
export interface FetchInit extends Record<string, any> {
headers?: Record<string, string>;
method?: AxiosRequestConfig['method'];
body?: FormData | any;
extra?: any;
}
export type AxiosTransformer = (
config: AxiosRequestConfig,
input?: RequestInfo,
init?: FetchInit,
) => AxiosRequestConfig;
export type AxiosTransformer = (config: AxiosRequestConfig, input: string | undefined, init: FetchInit) => AxiosRequestConfig;
export type AxiosFetch = (input?: RequestInfo, init?: FetchInit) => Promise<Response>;
export type AxiosFetch = (input?: string, init?: FetchInit) => Promise<Response>;

@@ -22,11 +19,11 @@ /**

*/
const axiosFetch: (axios: AxiosInstance, transformer?: AxiosTransformer) => AxiosFetch = (
axios,
transformer = (config) => config,
) => async (
input,
init= {},
) => {
const rawHeaders: Record<string, string> = createAxiosHeaders(init.headers);
const lowerCasedHeaders = Object.keys(rawHeaders)
async function axiosFetch (
axios: AxiosInstance,
// Convert the `fetch` style arguments into a Axios style config
transformer?: AxiosTransformer,
input?: string,
init: FetchInit = {}
) {
const rawHeaders: Record<string, string> = init.headers || {};
const lowerCasedHeaders = Object.keys(rawHeaders).filter(key => rawHeaders[key])
.reduce<Record<string, string>>(

@@ -37,3 +34,3 @@ (acc, key) => {

},
{},
{}
);

@@ -46,5 +43,5 @@

const rawConfig: AxiosRequestConfig = {
url: getUrl(input),
method: (init.method as AxiosRequestConfig['method']) || 'GET',
data: init.body,
url: input,
method: init.method || 'GET',
data: typeof init.body === 'undefined' || init.body instanceof FormData ? init.body : String(init.body),
headers: lowerCasedHeaders,

@@ -55,6 +52,6 @@ // Force the response to an arraybuffer type. Without this, the Response

// NOTE: Don't use 'stream' because it's not supported in the browser
responseType: 'arraybuffer',
responseType: 'arraybuffer'
};
const config = transformer(rawConfig, input, init);
const config = transformer ? transformer(rawConfig, input, init) : rawConfig;

@@ -72,11 +69,13 @@ let result;

const fetchHeaders = new FetchHeaders(result.headers);
return new Response(result.data, {
status: result.status,
statusText: result.statusText,
headers: createFetchHeaders(result.headers),
headers: fetchHeaders
});
};
}
export function buildAxiosFetch (axios: AxiosInstance, transformer?: AxiosTransformer): AxiosFetch {
return axiosFetch(axios, transformer);
return axiosFetch.bind(undefined, axios, transformer);
}
"use strict";
// Copied and edited from axios@0.21.1 because types aren't available in version 0.17
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJ0eXBlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEscUZBQXFGIiwic291cmNlc0NvbnRlbnQiOlsiLy8gQ29waWVkIGFuZCBlZGl0ZWQgZnJvbSBheGlvc0AwLjIxLjEgYmVjYXVzZSB0eXBlcyBhcmVuJ3QgYXZhaWxhYmxlIGluIHZlcnNpb24gMC4xN1xuXG5leHBvcnQgdHlwZSBNZXRob2QgPVxuICB8ICdnZXQnIHwgJ0dFVCdcbiAgfCAnZGVsZXRlJyB8ICdERUxFVEUnXG4gIHwgJ2hlYWQnIHwgJ0hFQUQnXG4gIHwgJ29wdGlvbnMnIHwgJ09QVElPTlMnXG4gIHwgJ3Bvc3QnIHwgJ1BPU1QnXG4gIHwgJ3B1dCcgfCAnUFVUJ1xuICB8ICdwYXRjaCcgfCAnUEFUQ0gnXG4gIHwgJ3B1cmdlJyB8ICdQVVJHRSdcbiAgfCAnbGluaycgfCAnTElOSydcbiAgfCAndW5saW5rJyB8ICdVTkxJTksnO1xuXG5leHBvcnQgdHlwZSBSZXNwb25zZVR5cGUgPVxuICB8ICdhcnJheWJ1ZmZlcidcbiAgfCAnYmxvYidcbiAgfCAnZG9jdW1lbnQnXG4gIHwgJ2pzb24nXG4gIHwgJ3RleHQnXG4gIHwgJ3N0cmVhbSc7XG5cbmV4cG9ydCBpbnRlcmZhY2UgQXhpb3NSZXF1ZXN0Q29uZmlnIHtcbiAgdXJsPzogc3RyaW5nO1xuICBtZXRob2Q/OiBNZXRob2Q7XG4gIGhlYWRlcnM/OiBhbnk7XG4gIGRhdGE/OiBhbnk7XG4gIHJlc3BvbnNlVHlwZT86IFJlc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W55XG5cbmV4cG9ydCBpbnRlcmZhY2UgQXhpb3NJbnN0YW5jZSB7XG4gIHJlcXVlc3Q8VCA9IGFueT4oY29uZmlnOiBBeGlvc1JlcXVlc3RDb25maWcpOiBBeGlvc1Byb21pc2U8VD47XG59XG4iXX0=

@@ -41,11 +41,2 @@ // Copied and edited from axios@0.21.1 because types aren't available in version 0.17

export interface AxiosError<T = never> extends Error {
config: AxiosRequestConfig;
code?: string;
request?: any;
response?: AxiosResponse<T>;
isAxiosError: boolean;
toJSON: () => object;
}
export type AxiosPromise<T = any> = Promise<AxiosResponse<T>> & any

@@ -52,0 +43,0 @@

@@ -25,4 +25,3 @@ {

"src/**/*",
"bin/*",
"test/**/*"
"bin/*"
],

@@ -29,0 +28,0 @@ "exclude": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc