fix(dependencies): update to latest standards
This commit is contained in:
@ -4,21 +4,26 @@ import { request } from './smartrequest.request';
|
||||
|
||||
import * as plugins from './smartrequest.plugins';
|
||||
|
||||
export const getBinary = async (domainArg: string, optionsArg: interfaces.ISmartRequestOptions = {}) => {
|
||||
const done = plugins.smartq.defer();
|
||||
export const getBinary = async (
|
||||
domainArg: string,
|
||||
optionsArg: interfaces.ISmartRequestOptions = {}
|
||||
) => {
|
||||
const done = plugins.smartpromise.defer();
|
||||
const response = await request(domainArg, optionsArg, true);
|
||||
const data = [];
|
||||
|
||||
response.on('data', function(chunk) {
|
||||
response
|
||||
.on('data', function(chunk) {
|
||||
data.push(chunk);
|
||||
}).on('end', function() {
|
||||
})
|
||||
.on('end', function() {
|
||||
//at this point data is an array of Buffers
|
||||
//so Buffer.concat() can make us a new Buffer
|
||||
//of all of them together
|
||||
const buffer = Buffer.concat(data);
|
||||
response.body = buffer.toString('binary');
|
||||
done.resolve();
|
||||
});
|
||||
});
|
||||
await done.promise;
|
||||
return response;
|
||||
}
|
||||
};
|
||||
|
@ -6,19 +6,24 @@ import { request } from './smartrequest.request';
|
||||
/**
|
||||
* gets Json and puts the right headers + handles response aggregation
|
||||
* @param domainArg
|
||||
* @param optionsArg
|
||||
* @param optionsArg
|
||||
*/
|
||||
export const getJson = async (domainArg: string, optionsArg: interfaces.ISmartRequestOptions = {}) => {
|
||||
export const getJson = async (
|
||||
domainArg: string,
|
||||
optionsArg: interfaces.ISmartRequestOptions = {}
|
||||
) => {
|
||||
optionsArg.method = 'GET';
|
||||
optionsArg.headers = {
|
||||
...optionsArg.headers,
|
||||
|
||||
}
|
||||
...optionsArg.headers
|
||||
};
|
||||
let response = await request(domainArg, optionsArg);
|
||||
return response;
|
||||
};
|
||||
|
||||
export const postJson = async (domainArg: string, optionsArg: interfaces.ISmartRequestOptions = {}) => {
|
||||
export const postJson = async (
|
||||
domainArg: string,
|
||||
optionsArg: interfaces.ISmartRequestOptions = {}
|
||||
) => {
|
||||
optionsArg.method = 'POST';
|
||||
if (
|
||||
typeof optionsArg.requestBody === 'object' &&
|
||||
@ -39,14 +44,20 @@ export const postJson = async (domainArg: string, optionsArg: interfaces.ISmartR
|
||||
return response;
|
||||
};
|
||||
|
||||
export const putJson = async (domainArg: string, optionsArg: interfaces.ISmartRequestOptions = {}) => {
|
||||
export const putJson = async (
|
||||
domainArg: string,
|
||||
optionsArg: interfaces.ISmartRequestOptions = {}
|
||||
) => {
|
||||
optionsArg.method = 'PUT';
|
||||
let response = await request(domainArg, optionsArg);
|
||||
return response;
|
||||
};
|
||||
|
||||
export const delJson = async (domainArg: string, optionsArg: interfaces.ISmartRequestOptions = {}) => {
|
||||
export const delJson = async (
|
||||
domainArg: string,
|
||||
optionsArg: interfaces.ISmartRequestOptions = {}
|
||||
) => {
|
||||
optionsArg.method = 'DELETE';
|
||||
let response = await request(domainArg, optionsArg);
|
||||
return response;
|
||||
};
|
||||
};
|
||||
|
@ -2,6 +2,6 @@ import * as url from 'url';
|
||||
import * as http from 'http';
|
||||
import * as https from 'https';
|
||||
|
||||
import * as smartq from 'smartq';
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
|
||||
export { url, http, https, smartq };
|
||||
export { url, http, https, smartpromise };
|
||||
|
@ -5,11 +5,11 @@ import * as interfaces from './smartrequest.interfaces';
|
||||
import { IncomingMessage } from 'http';
|
||||
|
||||
export interface extendedIncomingMessage extends IncomingMessage {
|
||||
body: any
|
||||
};
|
||||
body: any;
|
||||
}
|
||||
|
||||
let buildResponse = (incomingMessageArg: IncomingMessage): Promise<extendedIncomingMessage> => {
|
||||
let done = plugins.smartq.defer<extendedIncomingMessage>();
|
||||
let done = plugins.smartpromise.defer<extendedIncomingMessage>();
|
||||
// Continuously update stream with data
|
||||
let body = '';
|
||||
incomingMessageArg.on('data', function(chunkArg) {
|
||||
@ -32,7 +32,7 @@ export let request = async (
|
||||
optionsArg: interfaces.ISmartRequestOptions = {},
|
||||
streamArg: boolean = false
|
||||
): Promise<extendedIncomingMessage> => {
|
||||
let done = plugins.smartq.defer<any>();
|
||||
let done = plugins.smartpromise.defer<any>();
|
||||
let parsedUrl: plugins.url.Url;
|
||||
if (domainArg) {
|
||||
parsedUrl = plugins.url.parse(domainArg);
|
||||
|
Reference in New Issue
Block a user