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

@portal-hq/utils

Package Overview
Dependencies
Maintainers
7
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@portal-hq/utils - npm Package Compare versions

Comparing version 0.2.21 to 0.2.22-beta1

12

lib/commonjs/http-request/index.js

@@ -18,4 +18,9 @@ "use strict";

// Sends the request with a formatted request body
const body = this.prepareBody();
this.request.send(body);
if (['POST', 'PUT'].includes(this.method)) {
const body = this.prepareBody();
this.request.send(body);
}
else {
this.request.send();
}
// Adds an event listener for when the request state changes

@@ -57,2 +62,5 @@ this.request.onreadystatechange = () => {

}
else if (this.headers['Content-Type'] === 'text/plain') {
return this.body;
}
else {

@@ -59,0 +67,0 @@ // Otherwise, build a serialized string

@@ -61,3 +61,18 @@ "use strict";

}
put(path, options) {
return __awaiter(this, void 0, void 0, function* () {
const requestOptions = {
method: 'PUT',
url: `${this.baseUrl}${path}`,
};
requestOptions.headers = this.buildHeaders(options && options.headers ? options.headers : {});
if (options && options.body) {
requestOptions.body = options.body;
}
const request = new index_1.HttpRequest(requestOptions);
const response = (yield request.send());
return response;
});
}
}
exports.default = HttpRequester;

@@ -16,4 +16,9 @@ import { HttpError } from '../errors';

// Sends the request with a formatted request body
const body = this.prepareBody();
this.request.send(body);
if (['POST', 'PUT'].includes(this.method)) {
const body = this.prepareBody();
this.request.send(body);
}
else {
this.request.send();
}
// Adds an event listener for when the request state changes

@@ -55,2 +60,5 @@ this.request.onreadystatechange = () => {

}
else if (this.headers['Content-Type'] === 'text/plain') {
return this.body;
}
else {

@@ -57,0 +65,0 @@ // Otherwise, build a serialized string

@@ -59,3 +59,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

}
put(path, options) {
return __awaiter(this, void 0, void 0, function* () {
const requestOptions = {
method: 'PUT',
url: `${this.baseUrl}${path}`,
};
requestOptions.headers = this.buildHeaders(options && options.headers ? options.headers : {});
if (options && options.body) {
requestOptions.body = options.body;
}
const request = new HttpRequest(requestOptions);
const response = (yield request.send());
return response;
});
}
}
export default HttpRequester;

2

package.json
{
"name": "@portal-hq/utils",
"version": "0.2.21",
"version": "0.2.22-beta1",
"main": "lib/commonjs/index",

@@ -5,0 +5,0 @@ "module": "lib/esm/index",

@@ -30,4 +30,8 @@ import {

// Sends the request with a formatted request body
const body = this.prepareBody()
this.request.send(body)
if (['POST', 'PUT'].includes(this.method)) {
const body = this.prepareBody()
this.request.send(body)
} else {
this.request.send()
}

@@ -67,6 +71,8 @@ // Adds an event listener for when the request state changes

private prepareBody(): string {
private prepareBody(): any {
if (this.headers['Content-Type'] === 'application/json') {
// Stringify if we're declaring this request to be a JSON request
return JSON.stringify(this.body)
} else if (this.headers['Content-Type'] === 'text/plain') {
return this.body
} else {

@@ -73,0 +79,0 @@ // Otherwise, build a serialized string

@@ -76,4 +76,24 @@ import { HttpRequest } from '../index'

}
public async put<T>(path: string, options: HttpOptions): Promise<T> {
const requestOptions = {
method: 'PUT',
url: `${this.baseUrl}${path}`,
} as HttpRequestOptions
requestOptions.headers = this.buildHeaders(
options && options.headers ? options.headers : {},
)
if (options && options.body) {
requestOptions.body = options.body
}
const request = new HttpRequest(requestOptions)
const response = (await request.send()) as T
return response
}
}
export default HttpRequester
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