Socket
Socket
Sign inDemoInstall

@aspida/node-fetch

Package Overview
Dependencies
24
Maintainers
2
Versions
57
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.3.0 to 1.4.0

7

dist/index.d.ts
import { AspidaClient } from 'aspida';
import fetch, { RequestInit } from 'node-fetch';
import fetch, { RequestInit, Response } from 'node-fetch';
declare type FetchConfig = RequestInit & {
baseURL?: string;
throwHttpErrors?: boolean;
};
export declare class HTTPError extends Error {
response: Response;
constructor(response: Response);
}
declare const _default: (client?: typeof fetch, config?: FetchConfig | undefined) => AspidaClient<FetchConfig>;
export default _default;
//# sourceMappingURL=index.d.ts.map
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {

@@ -53,4 +66,15 @@ __assign = Object.assign || function(t) {

Object.defineProperty(exports, "__esModule", { value: true });
exports.HTTPError = void 0;
var aspida_1 = require("aspida");
var node_fetch_1 = __importDefault(require("node-fetch"));
var HTTPError = /** @class */ (function (_super) {
__extends(HTTPError, _super);
function HTTPError(response) {
var _this = _super.call(this, "HTTP Error: " + response.status + " " + response.statusText) || this;
_this.response = response;
return _this;
}
return HTTPError;
}(Error));
exports.HTTPError = HTTPError;
exports.default = (function (client, config) {

@@ -70,3 +94,3 @@ if (client === void 0) { client = node_fetch_1.default; }

request = aspida_1.optionToRequest(params, type);
return [4 /*yield*/, client("" + ((_c = (_b = request === null || request === void 0 ? void 0 : request.config) === null || _b === void 0 ? void 0 : _b.baseURL) !== null && _c !== void 0 ? _c : baseURL) + url + ((request === null || request === void 0 ? void 0 : request.query) ? "?" + aspida_1.dataToURLString(request.query) : ''), __assign(__assign(__assign({ method: method }, config), request === null || request === void 0 ? void 0 : request.config), { body: request === null || request === void 0 ? void 0 : request.httpBody, headers: __assign(__assign(__assign({}, config === null || config === void 0 ? void 0 : config.headers), (_d = request === null || request === void 0 ? void 0 : request.config) === null || _d === void 0 ? void 0 : _d.headers), request === null || request === void 0 ? void 0 : request.headers) }))];
return [4 /*yield*/, client("" + ((_c = (_b = request === null || request === void 0 ? void 0 : request.config) === null || _b === void 0 ? void 0 : _b.baseURL) !== null && _c !== void 0 ? _c : baseURL) + url + ((request === null || request === void 0 ? void 0 : request.query) ? "?" + aspida_1.dataToURLString(request.query) : ''), __assign(__assign(__assign({ method: method }, config), request === null || request === void 0 ? void 0 : request.config), { body: request === null || request === void 0 ? void 0 : request.httpBody, headers: __assign(__assign(__assign({}, config === null || config === void 0 ? void 0 : config.headers), (_d = request === null || request === void 0 ? void 0 : request.config) === null || _d === void 0 ? void 0 : _d.headers), request === null || request === void 0 ? void 0 : request.headers) })).then(function (res) { return (!res.ok && (config === null || config === void 0 ? void 0 : config.throwHttpErrors) ? Promise.reject(new HTTPError(res)) : res); })];
case 1:

@@ -73,0 +97,0 @@ res = _e.sent();

4

package.json
{
"name": "@aspida/node-fetch",
"version": "1.3.0",
"version": "1.4.0",
"description": "node-fetch client for aspida",

@@ -29,4 +29,4 @@ "author": "Solufa <solufa2020@gmail.com>",

"dependencies": {
"aspida": "^1.3.0"
"aspida": "^1.4.0"
}
}

@@ -49,4 +49,4 @@ # @aspida/node-fetch

```typescript
import fetch from "node-fetch"
import aspida from "@aspida/node-fetch"
import fetch, { Response } from "node-fetch"
import aspida, { HTTPError } from "@aspida/node-fetch"
import api from "../api/$api"

@@ -67,6 +67,14 @@

const user = await client.v1.users._userId(userId).$get()
console.log(user)
// req -> GET: https://example.com/api/v1/users/0
// res -> { id: 0, name: "mario" }
try {
const user = await client.v1.users._userId(userId).$get()
console.log(user)
// req -> GET: https://example.com/api/v1/users/0
// res -> { id: 0, name: "mario" }
} catch (e: HTTPError | Error) {
if (e instanceof HTTPError) {
console.log(e.response instanceof Response) // true
} else {
console.log(e.message)
}
}
})()

@@ -73,0 +81,0 @@ ```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc