@faasjs/request 0.0.3-beta.101 → 0.0.3-beta.102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +6 -3
- package/dist/index.mjs +7 -4
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -49,11 +49,21 @@ type RequestOptions = {
|
|
|
49
49
|
* Create a write stream to download a file.
|
|
50
50
|
*
|
|
51
51
|
* ```ts
|
|
52
|
+
* import { createWriteStream } from 'fs'
|
|
53
|
+
*
|
|
52
54
|
* const stream = createWriteStream('filepath')
|
|
53
55
|
* await request('https://example.com', { downloadStream: stream })
|
|
54
56
|
* ```
|
|
55
57
|
*/
|
|
56
58
|
downloadStream?: NodeJS.WritableStream;
|
|
59
|
+
/**
|
|
60
|
+
* Path of downloading a file from the server.
|
|
61
|
+
*
|
|
62
|
+
* ```ts
|
|
63
|
+
* await request('https://example.com', { downloadFile: 'filepath' })
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
downloadFile?: string;
|
|
57
67
|
pfx?: Buffer;
|
|
58
68
|
passphrase?: string;
|
|
59
69
|
agent?: boolean;
|
|
@@ -83,6 +93,7 @@ declare function querystringify(obj: any): string;
|
|
|
83
93
|
* @param {string=} options.auth Auth, format: user:password
|
|
84
94
|
* @param {string=} options.file Upload file path
|
|
85
95
|
* @param {WritableStream=} options.downloadStream Download stream
|
|
96
|
+
* @param {string=} options.downloadFile Download to file
|
|
86
97
|
* @param {Buffer=} options.pfx pfx
|
|
87
98
|
* @param {string=} options.passphrase passphrase
|
|
88
99
|
* @param {boolean=} options.agent agent
|
|
@@ -91,6 +102,6 @@ declare function querystringify(obj: any): string;
|
|
|
91
102
|
* @returns {promise}
|
|
92
103
|
* @url https://faasjs.com/doc/request.html
|
|
93
104
|
*/
|
|
94
|
-
declare function request<T = any>(url: string, { headers, method, query, body, timeout, auth, file, downloadStream, pfx, passphrase, agent, parse, logger, }?: RequestOptions): Promise<Response<T>>;
|
|
105
|
+
declare function request<T = any>(url: string, { headers, method, query, body, timeout, auth, file, downloadStream, downloadFile, pfx, passphrase, agent, parse, logger, }?: RequestOptions): Promise<Response<T>>;
|
|
95
106
|
|
|
96
107
|
export { Request, RequestOptions, Response, querystringify, request, setMock };
|
package/dist/index.d.ts
CHANGED
|
@@ -49,11 +49,21 @@ type RequestOptions = {
|
|
|
49
49
|
* Create a write stream to download a file.
|
|
50
50
|
*
|
|
51
51
|
* ```ts
|
|
52
|
+
* import { createWriteStream } from 'fs'
|
|
53
|
+
*
|
|
52
54
|
* const stream = createWriteStream('filepath')
|
|
53
55
|
* await request('https://example.com', { downloadStream: stream })
|
|
54
56
|
* ```
|
|
55
57
|
*/
|
|
56
58
|
downloadStream?: NodeJS.WritableStream;
|
|
59
|
+
/**
|
|
60
|
+
* Path of downloading a file from the server.
|
|
61
|
+
*
|
|
62
|
+
* ```ts
|
|
63
|
+
* await request('https://example.com', { downloadFile: 'filepath' })
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
downloadFile?: string;
|
|
57
67
|
pfx?: Buffer;
|
|
58
68
|
passphrase?: string;
|
|
59
69
|
agent?: boolean;
|
|
@@ -83,6 +93,7 @@ declare function querystringify(obj: any): string;
|
|
|
83
93
|
* @param {string=} options.auth Auth, format: user:password
|
|
84
94
|
* @param {string=} options.file Upload file path
|
|
85
95
|
* @param {WritableStream=} options.downloadStream Download stream
|
|
96
|
+
* @param {string=} options.downloadFile Download to file
|
|
86
97
|
* @param {Buffer=} options.pfx pfx
|
|
87
98
|
* @param {string=} options.passphrase passphrase
|
|
88
99
|
* @param {boolean=} options.agent agent
|
|
@@ -91,6 +102,6 @@ declare function querystringify(obj: any): string;
|
|
|
91
102
|
* @returns {promise}
|
|
92
103
|
* @url https://faasjs.com/doc/request.html
|
|
93
104
|
*/
|
|
94
|
-
declare function request<T = any>(url: string, { headers, method, query, body, timeout, auth, file, downloadStream, pfx, passphrase, agent, parse, logger, }?: RequestOptions): Promise<Response<T>>;
|
|
105
|
+
declare function request<T = any>(url: string, { headers, method, query, body, timeout, auth, file, downloadStream, downloadFile, pfx, passphrase, agent, parse, logger, }?: RequestOptions): Promise<Response<T>>;
|
|
95
106
|
|
|
96
107
|
export { Request, RequestOptions, Response, querystringify, request, setMock };
|
package/dist/index.js
CHANGED
|
@@ -61,6 +61,7 @@ async function request(url$1, {
|
|
|
61
61
|
auth,
|
|
62
62
|
file,
|
|
63
63
|
downloadStream,
|
|
64
|
+
downloadFile,
|
|
64
65
|
pfx,
|
|
65
66
|
passphrase,
|
|
66
67
|
agent,
|
|
@@ -124,9 +125,11 @@ async function request(url$1, {
|
|
|
124
125
|
const req = protocol.request(options, function(res) {
|
|
125
126
|
if (downloadStream) {
|
|
126
127
|
res.pipe(downloadStream);
|
|
127
|
-
downloadStream.on("finish",
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
downloadStream.on("finish", () => resolve(void 0));
|
|
129
|
+
} else if (downloadFile) {
|
|
130
|
+
const stream = fs.createWriteStream(downloadFile);
|
|
131
|
+
res.pipe(stream);
|
|
132
|
+
stream.on("finish", () => resolve(void 0));
|
|
130
133
|
} else {
|
|
131
134
|
const raw = [];
|
|
132
135
|
res.on("data", (chunk) => {
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as http from 'http';
|
|
2
2
|
import * as https from 'https';
|
|
3
3
|
import { URL } from 'url';
|
|
4
|
-
import { readFileSync } from 'fs';
|
|
4
|
+
import { createWriteStream, readFileSync } from 'fs';
|
|
5
5
|
import { basename } from 'path';
|
|
6
6
|
import { Logger } from '@faasjs/logger';
|
|
7
7
|
|
|
@@ -38,6 +38,7 @@ async function request(url, {
|
|
|
38
38
|
auth,
|
|
39
39
|
file,
|
|
40
40
|
downloadStream,
|
|
41
|
+
downloadFile,
|
|
41
42
|
pfx,
|
|
42
43
|
passphrase,
|
|
43
44
|
agent,
|
|
@@ -101,9 +102,11 @@ async function request(url, {
|
|
|
101
102
|
const req = protocol.request(options, function(res) {
|
|
102
103
|
if (downloadStream) {
|
|
103
104
|
res.pipe(downloadStream);
|
|
104
|
-
downloadStream.on("finish",
|
|
105
|
-
|
|
106
|
-
|
|
105
|
+
downloadStream.on("finish", () => resolve(void 0));
|
|
106
|
+
} else if (downloadFile) {
|
|
107
|
+
const stream = createWriteStream(downloadFile);
|
|
108
|
+
res.pipe(stream);
|
|
109
|
+
stream.on("finish", () => resolve(void 0));
|
|
107
110
|
} else {
|
|
108
111
|
const raw = [];
|
|
109
112
|
res.on("data", (chunk) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/request",
|
|
3
|
-
"version": "0.0.3-beta.
|
|
3
|
+
"version": "0.0.3-beta.102",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@faasjs/logger": "0.0.3-beta.
|
|
24
|
+
"@faasjs/logger": "0.0.3-beta.102"
|
|
25
25
|
},
|
|
26
26
|
"engines": {
|
|
27
27
|
"npm": ">=8.0.0",
|