@doctadevs/utils
Advanced tools
Comparing version 0.0.21 to 0.0.22
@@ -1,2 +0,2 @@ | ||
import { BodyInit } from 'node-fetch'; | ||
import 'isomorphic-fetch'; | ||
export declare type RequestOptions<DataType = BodyInit> = { | ||
@@ -3,0 +3,0 @@ url: string; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.request = void 0; | ||
const node_fetch_1 = __importDefault(require("node-fetch")); | ||
const request = async ({ url, method = 'GET', data, queryParams = {}, token = '', contentType = 'json', }) => { | ||
let fetchFunction; | ||
try { | ||
fetchFunction = window.fetch.bind(window); | ||
} | ||
catch { | ||
fetchFunction = node_fetch_1.default; | ||
} | ||
return fetchFunction(`${url}${!Object.keys(queryParams).length | ||
? '' | ||
: `?${Object.entries(queryParams) | ||
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`) | ||
.join('&')}`}`, { | ||
...(method !== 'GET' ? { body: JSON.stringify(data) } : {}), | ||
headers: { | ||
...(token ? { authorization: `Bearer ${token}` } : {}), | ||
'content-type': contentType, | ||
}, | ||
method, | ||
}).then((response) => response.json()); | ||
}; | ||
require("isomorphic-fetch"); | ||
const request = async ({ url, method = 'GET', data, queryParams = {}, token = '', contentType = 'json', }) => fetch(`${url}${!Object.keys(queryParams).length | ||
? '' | ||
: `?${Object.entries(queryParams) | ||
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`) | ||
.join('&')}`}`, { | ||
...(method !== 'GET' ? { body: JSON.stringify(data) } : {}), | ||
headers: { | ||
...(token ? { authorization: `Bearer ${token}` } : {}), | ||
'content-type': contentType, | ||
}, | ||
method, | ||
}).then((response) => response.json()); | ||
exports.request = request; | ||
//# sourceMappingURL=http.js.map |
{ | ||
"name": "@doctadevs/utils", | ||
"version": "0.0.21", | ||
"version": "0.0.22", | ||
"main": "dist/index.js", | ||
@@ -22,4 +22,4 @@ "types": "dist/index.d.ts", | ||
"@types/debug": "^4.1.6", | ||
"@types/isomorphic-fetch": "^0.0.35", | ||
"@types/node": "^16.3.2", | ||
"@types/node-fetch": "^2.5.11", | ||
"@typescript-eslint/eslint-plugin": "^4.4.1", | ||
@@ -38,5 +38,5 @@ "@typescript-eslint/parser": "^4.28.1", | ||
"@types/uuid": "^8.3.1", | ||
"node-fetch": "^2.6.1", | ||
"isomorphic-fetch": "^3.0.0", | ||
"uuid": "^8.3.2" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import fetch, { BodyInit, Response } from 'node-fetch'; | ||
import 'isomorphic-fetch'; | ||
@@ -19,10 +19,4 @@ export type RequestOptions<DataType = BodyInit> = { | ||
contentType = 'json', | ||
}: RequestOptions<DataT>) => { | ||
let fetchFunction: Function; | ||
try { | ||
fetchFunction = window.fetch.bind(window); | ||
} catch { | ||
fetchFunction = fetch; | ||
} | ||
return fetchFunction( | ||
}: RequestOptions<DataT>) => | ||
fetch( | ||
`${url}${ | ||
@@ -44,2 +38,1 @@ !Object.keys(queryParams).length | ||
).then((response: Response) => response.json()); | ||
}; |
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
17027
299
1
+ Addedisomorphic-fetch@^3.0.0
+ Addedisomorphic-fetch@3.0.0(transitive)
+ Addedwhatwg-fetch@3.6.20(transitive)
- Removednode-fetch@^2.6.1