fix(now handles binary files): update
This commit is contained in:
parent
52fa217fda
commit
df48a06d3e
12
dist/index.d.ts
vendored
12
dist/index.d.ts
vendored
@ -1,7 +1,9 @@
|
|||||||
import * as interfaces from './smartrequest.interfaces';
|
import * as interfaces from './smartrequest.interfaces';
|
||||||
export { request } from './smartrequest.request';
|
import { extendedIncomingMessage } from './smartrequest.request';
|
||||||
|
export { request, extendedIncomingMessage } from './smartrequest.request';
|
||||||
export { ISmartRequestOptions } from './smartrequest.interfaces';
|
export { ISmartRequestOptions } from './smartrequest.interfaces';
|
||||||
export declare let get: (domainArg: string, optionsArg?: interfaces.ISmartRequestOptions) => Promise<Response>;
|
export declare let get: (domainArg: string, optionsArg?: interfaces.ISmartRequestOptions) => Promise<extendedIncomingMessage>;
|
||||||
export declare let post: (domainArg: string, optionsArg?: interfaces.ISmartRequestOptions) => Promise<Response>;
|
export declare let getBinary: (domainArg: string, optionsArg?: interfaces.ISmartRequestOptions) => Promise<void>;
|
||||||
export declare let put: (domainArg: string, optionsArg?: interfaces.ISmartRequestOptions) => Promise<Response>;
|
export declare let post: (domainArg: string, optionsArg?: interfaces.ISmartRequestOptions) => Promise<extendedIncomingMessage>;
|
||||||
export declare let del: (domainArg: string, optionsArg?: interfaces.ISmartRequestOptions) => Promise<Response>;
|
export declare let put: (domainArg: string, optionsArg?: interfaces.ISmartRequestOptions) => Promise<extendedIncomingMessage>;
|
||||||
|
export declare let del: (domainArg: string, optionsArg?: interfaces.ISmartRequestOptions) => Promise<extendedIncomingMessage>;
|
||||||
|
15
dist/index.js
vendored
15
dist/index.js
vendored
@ -16,6 +16,19 @@ exports.get = (domainArg, optionsArg = {}) => __awaiter(this, void 0, void 0, fu
|
|||||||
let response = yield smartrequest_request_1.request(domainArg, optionsArg);
|
let response = yield smartrequest_request_1.request(domainArg, optionsArg);
|
||||||
return response;
|
return response;
|
||||||
});
|
});
|
||||||
|
exports.getBinary = (domainArg, optionsArg = {}) => __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const response = yield smartrequest_request_1.request(domainArg, optionsArg, true);
|
||||||
|
var data = [];
|
||||||
|
response.on('data', function (chunk) {
|
||||||
|
data.push(chunk);
|
||||||
|
}).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('base64');
|
||||||
|
});
|
||||||
|
});
|
||||||
exports.post = (domainArg, optionsArg = {}) => __awaiter(this, void 0, void 0, function* () {
|
exports.post = (domainArg, optionsArg = {}) => __awaiter(this, void 0, void 0, function* () {
|
||||||
optionsArg.method = 'POST';
|
optionsArg.method = 'POST';
|
||||||
if (typeof optionsArg.requestBody === 'object' &&
|
if (typeof optionsArg.requestBody === 'object' &&
|
||||||
@ -42,4 +55,4 @@ exports.del = (domainArg, optionsArg = {}) => __awaiter(this, void 0, void 0, fu
|
|||||||
let response = yield smartrequest_request_1.request(domainArg, optionsArg);
|
let response = yield smartrequest_request_1.request(domainArg, optionsArg);
|
||||||
return response;
|
return response;
|
||||||
});
|
});
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBS0EsaUVBQWlEO0FBRWpELCtEQUFpRDtBQUF4Qyx5Q0FBQSxPQUFPLENBQUE7QUFHTCxRQUFBLEdBQUcsR0FBRyxDQUFPLFNBQWlCLEVBQUUsYUFBOEMsRUFBRSxFQUFFLEVBQUU7SUFDN0YsVUFBVSxDQUFDLE1BQU0sR0FBRyxLQUFLLENBQUM7SUFDMUIsSUFBSSxRQUFRLEdBQUcsTUFBTSw4QkFBTyxDQUFDLFNBQVMsRUFBRSxVQUFVLENBQUMsQ0FBQztJQUNwRCxPQUFPLFFBQVE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QUU7SUFDN0YsVUFBVSxDQUFDLE1BQU0sR0FBRyxLQUFLLENBQUM7SUFDMUIsSUFBSSxRQUFRLEdBQUcsTUFBTSw4QkFBTyxDQUFDLFNBQVMsRUFBRSxVQUFVLENBQUMsQ0FBQztJQUNwRCxPQUFPLFFBQVEsQ0FBQztBQUNsQixDQUFDLENBQUEsQ0FBQztBQUVTLFFBQUEsR0FBRyxHQUFHLENBQU8sU0FBaUIsRUFBRSxhQUE4QyxFQUFFLEVBQUUsRUFBRTtJQUM3RixVQUFVLENBQUMsTUFBTSxHQUFHLFFBQVEsQ0FBQztJQUM3QixJQUFJLFFBQVEsR0FBRyxNQUFNLDhCQUFPLENBQUMsU0FBUyxFQUFFLFVBQVUsQ0FBQyxDQUFDO0lBQ3BELE9BQU8sUUFBUSxDQUFDO0FBQ2xCLENBQUMsQ0FBQSxDQUFDIn0=
|
2
dist/smartrequest.request.d.ts
vendored
2
dist/smartrequest.request.d.ts
vendored
@ -4,4 +4,4 @@ import { IncomingMessage } from 'http';
|
|||||||
export interface extendedIncomingMessage extends IncomingMessage {
|
export interface extendedIncomingMessage extends IncomingMessage {
|
||||||
body: any;
|
body: any;
|
||||||
}
|
}
|
||||||
export declare let request: (domainArg: string, optionsArg?: interfaces.ISmartRequestOptions, streamArg?: boolean) => Promise<Response>;
|
export declare let request: (domainArg: string, optionsArg?: interfaces.ISmartRequestOptions, streamArg?: boolean) => Promise<extendedIncomingMessage>;
|
||||||
|
2
dist/smartrequest.request.js
vendored
2
dist/smartrequest.request.js
vendored
@ -84,4 +84,4 @@ exports.request = (domainArg, optionsArg = {}, streamArg = false) => __awaiter(t
|
|||||||
}
|
}
|
||||||
return done.promise;
|
return done.promise;
|
||||||
});
|
});
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRyZXF1ZXN0LnJlcXVlc3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydHJlcX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N2QztRQUNELE9BQU8sQ0FBQyxFQUFFLENBQUMsT0FBTyxFQUFFLENBQUMsQ0FBQyxFQUFFO1lBQ3RCLE9BQU8sQ0FBQyxLQUFLLENBQUMsQ0FBQyxDQUFDLENBQUM7UUFDbkIsQ0FBQyxDQUFDLENBQUM7UUFDSCxPQUFPLENBQUMsR0FBRyxFQUFFLENBQUM7S0FDZjtTQUFNO1FBQ0wsTUFBTSxJQUFJLEtBQUssQ0FBQyx5QkFBeUIsU0FBUyxDQUFDLFFBQVEsRUFBRSxDQUFDLENBQUM7S0FDaEU7SUFDRCxPQUFPLElBQUksQ0FBQyxPQUFPLENBQUM7QUFDdEIsQ0FBQyxDQUFBLENBQUMifQ==
|
@ -1,7 +1,11 @@
|
|||||||
{
|
{
|
||||||
|
"npmts": {
|
||||||
|
"coverageTreshold": 60
|
||||||
|
},
|
||||||
"npmci": {
|
"npmci": {
|
||||||
"npmGlobalTools": [
|
"npmGlobalTools": [
|
||||||
"npmts"
|
"npmts"
|
||||||
]
|
],
|
||||||
|
"npmAccessLevel": "public"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "smartrequest",
|
"name": "smartrequest",
|
||||||
"version": "1.0.9",
|
"version": "1.0.9",
|
||||||
|
"private": false,
|
||||||
"description": "dropin replacement for request",
|
"description": "dropin replacement for request",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
@ -28,6 +29,5 @@
|
|||||||
"@types/node": "^10.3.3",
|
"@types/node": "^10.3.3",
|
||||||
"tapbundle": "^2.0.0",
|
"tapbundle": "^2.0.0",
|
||||||
"typings-test": "^1.0.3"
|
"typings-test": "^1.0.3"
|
||||||
},
|
}
|
||||||
"private": true
|
|
||||||
}
|
}
|
||||||
|
19
ts/index.ts
19
ts/index.ts
@ -3,9 +3,9 @@ import * as https from 'https';
|
|||||||
import * as plugins from './smartrequest.plugins';
|
import * as plugins from './smartrequest.plugins';
|
||||||
import * as interfaces from './smartrequest.interfaces';
|
import * as interfaces from './smartrequest.interfaces';
|
||||||
|
|
||||||
import { request } from './smartrequest.request';
|
import { request, extendedIncomingMessage } from './smartrequest.request';
|
||||||
|
|
||||||
export { request } from './smartrequest.request';
|
export { request, extendedIncomingMessage } from './smartrequest.request';
|
||||||
export { ISmartRequestOptions } from './smartrequest.interfaces';
|
export { ISmartRequestOptions } from './smartrequest.interfaces';
|
||||||
|
|
||||||
export let get = async (domainArg: string, optionsArg: interfaces.ISmartRequestOptions = {}) => {
|
export let get = async (domainArg: string, optionsArg: interfaces.ISmartRequestOptions = {}) => {
|
||||||
@ -14,6 +14,21 @@ export let get = async (domainArg: string, optionsArg: interfaces.ISmartRequestO
|
|||||||
return response;
|
return response;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export let getBinary = async (domainArg: string, optionsArg: interfaces.ISmartRequestOptions = {}) => {
|
||||||
|
const response = await request(domainArg, optionsArg, true);
|
||||||
|
var data = [];
|
||||||
|
|
||||||
|
response.on('data', function(chunk) {
|
||||||
|
data.push(chunk);
|
||||||
|
}).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('base64');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export let post = async (domainArg: string, optionsArg: interfaces.ISmartRequestOptions = {}) => {
|
export let post = async (domainArg: string, optionsArg: interfaces.ISmartRequestOptions = {}) => {
|
||||||
optionsArg.method = 'POST';
|
optionsArg.method = 'POST';
|
||||||
if (
|
if (
|
||||||
|
@ -31,7 +31,7 @@ export let request = async (
|
|||||||
domainArg: string,
|
domainArg: string,
|
||||||
optionsArg: interfaces.ISmartRequestOptions = {},
|
optionsArg: interfaces.ISmartRequestOptions = {},
|
||||||
streamArg: boolean = false
|
streamArg: boolean = false
|
||||||
): Promise<Response> => {
|
): Promise<extendedIncomingMessage> => {
|
||||||
let done = plugins.q.defer<any>();
|
let done = plugins.q.defer<any>();
|
||||||
let parsedUrl: plugins.url.Url;
|
let parsedUrl: plugins.url.Url;
|
||||||
if (domainArg) {
|
if (domainArg) {
|
||||||
|
Loading…
Reference in New Issue
Block a user