Socket
Socket
Sign inDemoInstall

@nestia/fetcher

Package Overview
Dependencies
1
Maintainers
0
Versions
321
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.2.6 to 3.3.0-dev.20240624

2

lib/EncryptedFetcher.js

@@ -77,3 +77,3 @@ "use strict";

: function () { return function () { return connection.encryption; }; };
return [2 /*return*/, FetcherBase_1.FetcherBase.fetch({
return [2 /*return*/, FetcherBase_1.FetcherBase.request({
className: "EncryptedFetcher",

@@ -80,0 +80,0 @@ encode: ((_c = route.request) === null || _c === void 0 ? void 0 : _c.encrypted) === true

@@ -68,4 +68,9 @@ /// <reference lib="dom" />

*
* If you want to use custom `fetch` function instead of built-in function,
* If you want to use custom `fetch` function instead of built-in,
* assign your custom `fetch` function into this property.
*
* For reference, the `fetch` function has started to be supported
* since version 20 of NodeJS. Therefore, if you are using NodeJS
* version 19 or lower, you have to assign the `node-fetch` module
* into this property.
*/

@@ -72,0 +77,0 @@ fetch?: typeof fetch;

@@ -1,12 +0,1 @@

import { IConnection } from "../IConnection";
import { IFetchRoute } from "../IFetchRoute";
import { IPropagation } from "../IPropagation";
export declare namespace FetcherBase {
interface IProps {
className: string;
encode: (input: any, headers: Record<string, IConnection.HeaderValue | undefined>) => string;
decode: (input: string, headers: Record<string, IConnection.HeaderValue | undefined>) => any;
}
const fetch: (props: IProps) => <Input, Output>(connection: IConnection, route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">, input?: Input, stringify?: (input: Input) => string) => Promise<Output>;
const propagate: (props: IProps) => <Input>(connection: IConnection, route: IFetchRoute<"DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT">, input?: Input, stringify?: (input: Input) => string) => Promise<IPropagation<any, any>>;
}
export {};

@@ -85,14 +85,12 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FetcherBase = void 0;
var import2_1 = __importDefault(require("import2"));
var HttpError_1 = require("../HttpError");
var Singleton_1 = require("./Singleton");
/**
* @internal
*/
var FetcherBase;
(function (FetcherBase) {
var _this = this;
FetcherBase.fetch = function (props) {
FetcherBase.request = function (props) {
return function (connection, route, input, stringify) { return __awaiter(_this, void 0, void 0, function () {

@@ -123,14 +121,14 @@ var result;

return function (connection, route, input, stringify) { return __awaiter(_this, void 0, void 0, function () {
var headers, init, path, url, event, response, _a, result, _b, type, text, query, _c, _d, _e, _f, exp_1, _g;
var _h, _j, _k, _l, _m, _o, _p, _q, _r;
return __generator(this, function (_s) {
switch (_s.label) {
var headers, init, path, url, event, response, result, _a, type, text, query, _b, _c, _d, _e, exp_1, _f;
var _g, _h, _j, _k, _l, _m, _o, _p, _q;
return __generator(this, function (_r) {
switch (_r.label) {
case 0:
headers = __assign({}, ((_h = connection.headers) !== null && _h !== void 0 ? _h : {}));
headers = __assign({}, ((_g = connection.headers) !== null && _g !== void 0 ? _g : {}));
if (input !== undefined)
if (((_j = route.request) === null || _j === void 0 ? void 0 : _j.type) === undefined)
if (((_h = route.request) === null || _h === void 0 ? void 0 : _h.type) === undefined)
throw new Error("Error on ".concat(props.className, ".fetch(): no content-type being configured."));
else if (route.request.type !== "multipart/form-data")
headers["Content-Type"] = route.request.type;
init = __assign(__assign({}, ((_k = connection.options) !== null && _k !== void 0 ? _k : {})), { method: route.method, headers: (function () {
init = __assign(__assign({}, ((_j = connection.options) !== null && _j !== void 0 ? _j : {})), { method: route.method, headers: (function () {
var e_1, _a, e_2, _b;

@@ -174,7 +172,7 @@ var output = [];

// BODY TRANSFORM
((_l = route.request) === null || _l === void 0 ? void 0 : _l.type) === "application/x-www-form-urlencoded"
((_k = route.request) === null || _k === void 0 ? void 0 : _k.type) === "application/x-www-form-urlencoded"
? request_query_body(input)
: ((_m = route.request) === null || _m === void 0 ? void 0 : _m.type) === "multipart/form-data"
: ((_l = route.request) === null || _l === void 0 ? void 0 : _l.type) === "multipart/form-data"
? request_form_data_body(input)
: ((_o = route.request) === null || _o === void 0 ? void 0 : _o.type) !== "text/plain"
: ((_m = route.request) === null || _m === void 0 ? void 0 : _m.type) !== "text/plain"
? (stringify !== null && stringify !== void 0 ? stringify : JSON.stringify)(input)

@@ -197,15 +195,8 @@ : input, headers);

};
_s.label = 1;
_r.label = 1;
case 1:
_s.trys.push([1, 15, 16, 21]);
if (!((_p = connection.fetch) !== null && _p !== void 0)) return [3 /*break*/, 2];
_a = _p;
return [3 /*break*/, 4];
case 2: return [4 /*yield*/, polyfill.get()];
case 3:
_a = (_s.sent());
_s.label = 4;
case 4: return [4 /*yield*/, (_a)(url.href, init)];
case 5:
response = _s.sent();
_r.trys.push([1, 12, 13, 18]);
return [4 /*yield*/, ((_o = connection.fetch) !== null && _o !== void 0 ? _o : fetch)(url.href, init)];
case 2:
response = _r.sent();
event.respond_at = new Date();

@@ -221,9 +212,9 @@ event.status = response.status;

};
if (!(result.success === false)) return [3 /*break*/, 7];
if (!(result.success === false)) return [3 /*break*/, 4];
// WHEN FAILED
_b = result;
_a = result;
return [4 /*yield*/, response.text()];
case 6:
case 3:
// WHEN FAILED
_b.data = _s.sent();
_a.data = _r.sent();
type = response.headers.get("content-type");

@@ -236,51 +227,51 @@ if (method !== "fetch" &&

}
catch (_t) { }
return [3 /*break*/, 14];
case 7:
if (!(route.method === "HEAD")) return [3 /*break*/, 8];
catch (_s) { }
return [3 /*break*/, 11];
case 4:
if (!(route.method === "HEAD")) return [3 /*break*/, 5];
result.data = undefined;
return [3 /*break*/, 14];
case 8:
if (!(((_q = route.response) === null || _q === void 0 ? void 0 : _q.type) === "application/json")) return [3 /*break*/, 10];
return [3 /*break*/, 11];
case 5:
if (!(((_p = route.response) === null || _p === void 0 ? void 0 : _p.type) === "application/json")) return [3 /*break*/, 7];
return [4 /*yield*/, response.text()];
case 9:
text = _s.sent();
case 6:
text = _r.sent();
result.data = text.length ? JSON.parse(text) : undefined;
return [3 /*break*/, 14];
case 10:
if (!(((_r = route.response) === null || _r === void 0 ? void 0 : _r.type) === "application/x-www-form-urlencoded")) return [3 /*break*/, 12];
_c = URLSearchParams.bind;
return [3 /*break*/, 11];
case 7:
if (!(((_q = route.response) === null || _q === void 0 ? void 0 : _q.type) === "application/x-www-form-urlencoded")) return [3 /*break*/, 9];
_b = URLSearchParams.bind;
return [4 /*yield*/, response.text()];
case 11:
query = new (_c.apply(URLSearchParams, [void 0, _s.sent()]))();
case 8:
query = new (_b.apply(URLSearchParams, [void 0, _r.sent()]))();
result.data = route.parseQuery ? route.parseQuery(query) : query;
return [3 /*break*/, 14];
case 12:
_d = result;
_f = (_e = props).decode;
return [3 /*break*/, 11];
case 9:
_c = result;
_e = (_d = props).decode;
return [4 /*yield*/, response.text()];
case 13:
_d.data = _f.apply(_e, [_s.sent(), result.headers]);
_s.label = 14;
case 14:
case 10:
_c.data = _e.apply(_d, [_r.sent(), result.headers]);
_r.label = 11;
case 11:
event.output = result.data;
return [2 /*return*/, result];
case 15:
exp_1 = _s.sent();
case 12:
exp_1 = _r.sent();
throw exp_1;
case 16:
case 13:
event.completed_at = new Date();
if (!connection.logger) return [3 /*break*/, 20];
_s.label = 17;
case 17:
_s.trys.push([17, 19, , 20]);
if (!connection.logger) return [3 /*break*/, 17];
_r.label = 14;
case 14:
_r.trys.push([14, 16, , 17]);
return [4 /*yield*/, connection.logger(event)];
case 18:
_s.sent();
return [3 /*break*/, 20];
case 19:
_g = _s.sent();
return [3 /*break*/, 20];
case 20: return [7 /*endfinally*/];
case 21: return [2 /*return*/];
case 15:
_r.sent();
return [3 /*break*/, 17];
case 16:
_f = _r.sent();
return [3 /*break*/, 17];
case 17: return [7 /*endfinally*/];
case 18: return [2 /*return*/];
}

@@ -295,37 +286,2 @@ });

*/
var polyfill = new Singleton_1.Singleton(function () { return __awaiter(void 0, void 0, void 0, function () {
function is_node_process(m) {
return (m !== null &&
typeof m.process === "object" &&
m.process !== null &&
typeof m.process.versions === "object" &&
m.process.versions !== null &&
typeof m.process.versions.node !== "undefined");
}
var m, _a, _b;
var _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
if (!(typeof global === "object" && is_node_process(global))) return [3 /*break*/, 4];
m = global;
if (!((_c = m.fetch) !== null && _c !== void 0)) return [3 /*break*/, 1];
_a = _c;
return [3 /*break*/, 3];
case 1:
_b = m;
return [4 /*yield*/, (0, import2_1.default)("node-fetch")];
case 2:
_a = (_b.fetch = (_d.sent()).default);
_d.label = 3;
case 3:
_a;
return [2 /*return*/, m.fetch];
case 4: return [2 /*return*/, self.fetch];
}
});
}); });
/**
* @internal
*/
var request_query_body = function (input) {

@@ -332,0 +288,0 @@ var e_3, _a;

@@ -64,3 +64,3 @@ "use strict";

throw new Error("Error on PlainFetcher.fetch(): PlainFetcher doesn't have encryption ability. Use EncryptedFetcher instead.");
return [2 /*return*/, FetcherBase_1.FetcherBase.fetch({
return [2 /*return*/, FetcherBase_1.FetcherBase.request({
className: "PlainFetcher",

@@ -67,0 +67,0 @@ encode: function (input) { return input; },

{
"name": "@nestia/fetcher",
"version": "3.2.6",
"version": "3.3.0-dev.20240624",
"description": "Fetcher library of Nestia SDK",

@@ -38,6 +38,2 @@ "main": "lib/index.js",

},
"dependencies": {
"import2": "^1.0.3",
"node-fetch": "^2.6.7"
},
"files": [

@@ -44,0 +40,0 @@ "README.md",

@@ -88,3 +88,3 @@ import { AesPkcs5 } from "./AesPkcs5";

return FetcherBase.fetch({
return FetcherBase.request({
className: "EncryptedFetcher",

@@ -91,0 +91,0 @@ encode:

@@ -78,4 +78,9 @@ /// <reference lib="dom" />

*
* If you want to use custom `fetch` function instead of built-in function,
* If you want to use custom `fetch` function instead of built-in,
* assign your custom `fetch` function into this property.
*
* For reference, the `fetch` function has started to be supported
* since version 20 of NodeJS. Therefore, if you are using NodeJS
* version 19 or lower, you have to assign the `node-fetch` module
* into this property.
*/

@@ -82,0 +87,0 @@ fetch?: typeof fetch;

@@ -1,3 +0,1 @@

import import2 from "import2";
import { HttpError } from "../HttpError";

@@ -8,4 +6,6 @@ import { IConnection } from "../IConnection";

import { IPropagation } from "../IPropagation";
import { Singleton } from "./Singleton";
/**
* @internal
*/
export namespace FetcherBase {

@@ -24,3 +24,3 @@ export interface IProps {

export const fetch =
export const request =
(props: IProps) =>

@@ -140,5 +140,6 @@ async <Input, Output>(

// TRY FETCH
const response: Response = await (
connection.fetch ?? (await polyfill.get())
)(url.href, init);
const response: Response = await (connection.fetch ?? fetch)(
url.href,
init,
);
event.respond_at = new Date();

@@ -202,24 +203,2 @@ event.status = response.status;

*/
const polyfill = new Singleton(async (): Promise<typeof fetch> => {
function is_node_process(m: typeof global | null): boolean {
return (
m !== null &&
typeof m.process === "object" &&
m.process !== null &&
typeof m.process.versions === "object" &&
m.process.versions !== null &&
typeof m.process.versions.node !== "undefined"
);
}
if (typeof global === "object" && is_node_process(global)) {
const m: any = global as any;
m.fetch ??= ((await import2("node-fetch")) as any).default;
return (m as any).fetch;
}
return self.fetch;
});
/**
* @internal
*/
const request_query_body = (input: any): URLSearchParams => {

@@ -226,0 +205,0 @@ const q: URLSearchParams = new URLSearchParams();

@@ -70,3 +70,3 @@ import { IConnection } from "./IConnection";

);
return FetcherBase.fetch({
return FetcherBase.request({
className: "PlainFetcher",

@@ -73,0 +73,0 @@ encode: (input) => input,

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

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